Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Event Arguments in Action scriptblock of Register-ObjectEvent cmdlet

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

like image 721
tellingmachine Avatar asked Oct 08 '09 20:10

tellingmachine


1 Answers

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.

like image 148
dan-gph Avatar answered Oct 21 '22 13:10

dan-gph