CimIndicationEvents Happen
I hope you are finding this series on eventing in PowerShell helpful. Once you understand how to set up event subscriptions, I’m sure you are recognizing endless possibilities. Scripting this kind of management task can go a long way in filling in the gaps in your IT management strategy. If your budget allows, I’d recommend traditional management solutions, but being able to plug any holes with PowerShell is invaluable.
In the previous article, I introduced you to creating event subscriptions with WMI/CIM. Here is code that will work in Windows PowerShell to raise an event anytime the Spooler service changes.
PS C:\> $query="Select * from __InstanceModificationEvent within 10 where targetinstance isa 'Win32_Service' AND Targetinstance.Name='spooler'"
PS C:\> $SvcWatcher = New-Object System.Management.ManagementEventWatcher $query
PS C:\> Register-ObjectEvent -InputObject $Svcwatcher -sourceIdentifier SpoolerWatch -EventName EventArrived -MessageData "The spooler service has changed"
This event subscription isn’t taking any action, but I will get an event when something changes.
Want to read the full issue?