Question

Is it possible to access the Event arguments in the -Action scriptblock of the Register-ObjectEvent cmdlet? And if yes, how?

Was it helpful?

Solution

Yes. The EventArgs object is available inside the Action script block as a magical variable called $Event. This is what get-help Register-ObjectEvent -detail has to say:

From the MSDN documentation:

The value of the Action parameter can include the $Event, $EventSubscriber, $Sender, $SourceEventArgs, and $SourceArgs automatic variables, which provide information about the event to the Action script block. For more information, see about_Automatic_Variables.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top