8

I'm writing a C# Cmdlet that needs to get the value of a global script variable. How do I do it?

I noticed that the Runspace has SessionStateProxy.GetVariable method. Can I access the runspace from a C# Cmdlet?

Thanks!

1 Answer 1

8

If you're implementing a PSCmdlet use the this variable to access it like so:

this.SessionState.PSVariable.GetValue()
Sign up to request clarification or add additional context in comments.

2 Comments

or shorter: this.GetVariableValue(...)
Is there an option for a System.Management.Automation.Cmdlet?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.