MSSQL/WMI/PowerShell结合篇(二)创建WMI监控

 

文中所介绍的监控类型的WMI消费者主要为CommandLineEventConsumer、

LogFileEventConsumer 


详细介绍参阅以下链接: 
CommandLineEventConsumer 
LogFileEventConsumer 


下面以PowerShell脚本为例,介绍如何创建WMI事件监控 


一、LogFileEventConsumer示例 
1、创建EventFilter,对需要监控的事件进行过滤 
${EventNamespace} = "the event namespace which is to be monitored" 
${QueryLanguage} = 'WQL' 
${Namespace}="root\subscription" 
${ComputerName}="." 
${Query}= "WQL Query Statement"; 
${Name}="EventFilter Name" 
${NewFilter} = ([wmiclass]"\\${ComputerName}\${Namespace}:__EventFilter").CreateInstance() 
${NewFilter}.{QueryLanguage} = ${QueryLanguage} 
${NewFilter}.{Query} = ${Query} 
${NewFilter}.{EventNamespace} = ${EventNamespace} 
${NewFilter}.{Name} = ${Name} 
$result = $NewFilter.Put() 
2、创建Consumer,触发相应的动作 
${Text} ='the text which is to be logged' 
${FileName}="FileName" 
${IsUnicode}="true" 
${ComputerName}="." 
${Name}="EventConsumer Name"; 
${NewConsumer} = ([wmiclass]"\\${ComputerName}\root\subscription:LogFileEventConsumer").CreateInstance() 
${NewConsumer}.{Name} = ${Name} 
${NewConsumer}.{FileName} = ${FileName} 
${NewConsumer}.{IsUnicode} = ${IsUnicode} 
${NewConsumer}.{Text} = ${Text} 
$NewConsumer.Put() 
3、创建Binding,绑定EventFilter、Cousumer,使得事件被捕获时立即触发动作 
${Namespace}="root\subscription" 
${ComputerName}="." 
${NewBinding} = ([wmiclass]"\\${ComputerName}\${Namespace}:__FilterToConsumerBinding").CreateInstance() 
${NewBinding}.Filter = "\\${ComputerName}\ROOT\Subscription:__EventFilter.Name=`"EventFilter Name`"" 
${NewBinding}.{Consumer} ="\\${ComputerName}\ROOT\Subscription:LogFileEventConsumer.Name=`"EventConsumer Name`"" 
${NewBinding}.{MaintainSecurityContext} = ${FALSE} 
${NewBinding}.{SlowDownProviders} = ${FALSE} 
$NewBinding.Put() 
二、CommandLineEventConsumer示例 
1、创建EventFilter,对需要监控的事件进行过滤 
${EventNamespace} = "the event namespace which is to be monitored" 
${QueryLanguage} = 'WQL' 
${Namespace}="root\subscription" 
${ComputerName}="." 
${Query}= "WQL Query Statement"; 
${Name}="EventFilter Name" 
${NewFilter} = ([wmiclass]"\\${ComputerName}\${Namespace}:__EventFilter").CreateInstance() 
${NewFilter}.{QueryLanguage} = ${QueryLanguage} 
${NewFilter}.{Query} = ${Query} 
${NewFilter}.{EventNamespace} = ${EventNamespace} 
${NewFilter}.{Name} = ${Name} 
$result = $NewFilter.Put() 
2、创建Consumer,触发相应的动作(以执行PowerShell命令行为例) 
${Namespace}="root\subscription" 
${ComputerName}="." 
${Name}="EventConsumer Name"; 
$ExecutablePath="c:\xxx\xxx\powershell.exe" 
$CommandLineTemplate="powershell.exe -File D:\xxx\xxx.ps1" 
${NewConsumer} = ([wmiclass]"\\${ComputerName}\${Namespace}:CommandLineEventConsumer").CreateInstance() 
${NewConsumer}.{CommandLineTemplate} = ${CommandLineTemplate} 
${NewConsumer}.{ExecutablePath} = ${ExecutablePath} 
${NewConsumer}.{name}=${Name} 
$NewConsumer.Put() 
3、创建Binding,绑定EventFilter、Cousumer,使得事件被捕获时立即触发动作 
${Namespace}="root\subscription" 
${ComputerName}="." 
${NewBinding} = ([wmiclass]"\\${ComputerName}\${Namespace}:__FilterToConsumerBinding").CreateInstance() 
${NewBinding}.Filter = "\\${ComputerName}\ROOT\Subscription:__EventFilter.Name=`"EventFilter Name`"" 
${NewBinding}.{Consumer} ="\\${ComputerName}\ROOT\Subscription:CommandLineEventConsumer.Name=`"EventConsumer Name`"" 
${NewBinding}.{MaintainSecurityContext} = ${FALSE} 
${NewBinding}.{SlowDownProviders} = ${FALSE} 
$NewBinding.Put() 

 SD-WAN是介于虚拟专用网与MPLS之间的新推出的一种产品,它的效果比MPLS稍差,但比虚拟专用网好很多,最重要的是他的价格比起MPLS来说,价格十分亲民,另外如果两个需要专线联通的分支机构之家的距离越远,其效果比MPLS相差越小,所以SD-WAN出现以来,大大减少了企业的成本,越来越受到企业的青睐。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值