2010-01-03 70 views
2

對不起,英語不好。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

這個腳本怎麼了?

回答

0

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"} 

再次。對不起英語不好。只是糾正我,如果有錯誤:)