Powershell事件转发

问题描述:

对不起,英语不好。Powershell事件转发

我在PowerShell和事件转发机制中有一些麻烦。我试着这样做:

$remoteComputer = "." 
$session = New-PsSession $remoteComputer 

Unregister-Event CatchEvent -ErrorAction SilentlyContinue 
Invoke-Command $session { 

    ## The WMI query to detect a stopping service 
    $query = @" 
     SELECT * 
     FROM __instancecreationevent 
     WHERE TargetInstance ISA 'Win32_NtLogEvent' 
     and targetinstance.eventcode = '7036' 
"@ 
    Register-WmiEvent -Query $query "CatchEvent" -Forward 
} 
$null = Register-EngineEvent CatchEvent -Action { $GLOBAL:MyEvent = $event} 

$ MyEvent变量最后含有不是一个事件的信息,但System.String类的数据。 alt text http://eosfor.fileave.com/powershell.png

这个脚本怎么了?

Vasily Gusev给我一个answer

$query = "SELECT * FROM __instancecreationevent WHERE TargetInstance ISA 'Win32_NtLogEvent' AND TargetInstance.eventcode = '7036'" 
Register-WmiEvent -Query $query -ComputerName client1 -Action {write-host "Service Stopped"} 

再次。对不起英语不好。只是纠正我,如果有错误:)