Events are a staple of .NET developers looking to react to changes of an object, for example. A .NET class mimicking a coffee machine, for instance, would raise an event coffee dispensed whenever a coffee is ordered. We can react to three kinds of events in PowerShell, as well:
Cmdlet |
Event description |
Register-ObjectEvent |
Events of .NET objects, for instance, the exited event of a System.Diagnostics.Process |
Register-WmiEvent |
Events of WMI classes, for instance, an event that is raised whenever a new process starts |
Register-EngineEvent |
Events of the PowerShell engine, for instance, an event triggered when PowerShell is closing |
We will have a look at all three kinds of events through practical examples.