8

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

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.