Events Are Easy
Events are easy.
Events let you know when something happened, and respond to it if you choose.
Events are incredibly useful.
Because they let you run what you want, when you want.
Let's see how simple they are:
Creating Events
Events are easy to create.
To make a new event, simply run:
New-Event MyCustomEvent
This will output an event object.
If nothing subscribes to the event, the event will go in the queue
We can get events with:
Get-Event
We can handle these events whenever we want.
How about now?
Subscribing to Events
We can run code the millisecond something happens.
To do this, we can subscribe to the event.
There are two types of events we can subscribe to in PowerShell:
Engine events and object events.
Engine Events
We can create engine events with New-Event.
We can subscribe to engine events with Register-EngineEvent
$subscriber = Register-EngineEvent -SourceIdentifier "Hello...
Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE