The previous example showed something nice, but it also hinted about something that is not so pleasant: it is very difficult to deal with different events and distinguish among them. The best way to handle this problem is to use the helper eventhandler.ps1 script that ships with PSEventing and its utility functions:
Add-EventHandler($variable, $eventName, $script) will attach a script block as a handler for the given event.
Remove-EventHandler($variable, $eventName) lets us detach a previously attached event handler.
Do-Events($onlyOnce) will wait for events and process their event handlers one or more times.
The eventhandler.ps1 file is a part of the official PSEventing release files, but it is not ...