如何为PowerShell创建RunspaceConnectionInfo对象?

时间:2013-05-13 20:53:27

标签: c# .net powershell

我正在尝试使用

创建一个Runspace

System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(RunspaceConnectionInfo

但我无法弄清楚如何创建 RunspaceConnectionInfo 对象。它是抽象的,我能找到的唯一子类是 WSManConnectionInfo 对象。

我应该创建自己的RunspaceConnectionInfo子类吗?

2 个答案:

答案 0 :(得分:0)

CreateRunspace是一种静态方法。你需要像这样调用它:

PS D:\> $runspace = [System.Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace()
PS D:\> $runspace


Events                 :
ThreadOptions          : Default
JobManager             :
RunspaceConfiguration  : System.Management.Automation.Runspaces.RunspaceConfigForSingleShell
InitialSessionState    :
Version                : 3.0
RunspaceStateInfo      : BeforeOpen
RunspaceAvailability   : None
ConnectionInfo         :
OriginalConnectionInfo :
LanguageMode           :
ApartmentState         : Unknown
InstanceId             : 49589d51-38db-4532-9914-0fd7f3306819
SessionStateProxy      : System.Management.Automation.Runspaces.SessionStateProxy
Debugger               :



PS D:\>

答案 1 :(得分:0)

我正在进行更多挖掘,看起来远程电源shell运行在WSM​​an上,因此使用WSManConnectionInfo对象可以正常工作!