2014-03-01 90 views

回答

0

是的,你可以使用Register-WMIEvent。註冊事件後,如果您在Action參數中指定了一個,它將執行任意scriptblock

這裏有一個簡單的例子,其中只要創建一個名爲iexpore.exe過程中的腳本塊只寫入控制檯:

Register-WMIEvent -query "Select * From __InstanceCreationEvent within 3 Where TargetInstance ISA 'Win32_Process' and TargetInstance.Name ='iexplore.exe'" ` 
-sourceIdentifier "New IE Process" ` 
-action {Write-Host "A new Internet Explorer process has started!"} 

這裏是一個有用的Scripting Guy post concerning Event Monitoring,如果你有興趣進一步閱讀。請注意,Get-PSEvent現在被稱爲Get-Event