Powershell - 从C#中获取变量Cmdlet

问题描述:

我正在编写一个需要获取全局脚本变量值的C#Cmdlet。 我该怎么做?Powershell - 从C#中获取变量Cmdlet

我注意到Runspace有SessionStateProxy.GetVariable方法。 我可以从C#Cmdlet访问运行空间吗?

谢谢!

如果你正在实施一个PSCmdlet使用this变量来访问它,像这样:

this.SessionState.PSVariable.GetValue() 
+1

或更短:this.GetVariableValue(...) – 2013-12-29 16:31:58

+0

是否有一个'System.Management的选项。 Automation.Cmdlet'? – craig 2016-09-09 13:07:10