views:

164

answers:

1

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

+2  A: 

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:

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.

dangph