Is it possible to access the Event arguments in the -Action scriptblock of the Register-ObjectEvent cmdlet? And if yes, how?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With