简体   繁体   English

如何为PowerShell创建RunspaceConnectionInfo对象?

[英]How do I Create a RunspaceConnectionInfo object for PowerShell?

I am trying to create a Runspace using 我正在尝试使用创建一个运行空间

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

but I can't figure out how to create a RunspaceConnectionInfo object. 但是我不知道如何创建一个RunspaceConnectionInfo对象。 It is abstract and the only subclass for it I could find was a WSManConnectionInfo object. 它是抽象的,唯一可以找到的子类是WSManConnectionInfo对象。

Am I supposed to create my own RunspaceConnectionInfo subclass? 我应该创建自己的RunspaceConnectionInfo子类吗?

CreateRunspace is a static method. CreateRunspace是静态方法。 You need to invoke it like this: 您需要像这样调用它:

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:\>

我做了一些进一步的挖掘,看起来远程电源外壳在WSMan上运行,因此使用WSManConnectionInfo对象可以很好地工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我在本地主机上创建 RunSpace 而不提供 runspaceconnectioninfo 时,某些 PowerShell 模块(集群 cmdlet)不会被加载 - Some of the PowerShell module (Cluster cmdlets) does not get loaded when I create RunSpace on a localhost without providing runspaceconnectioninfo 如何创建可由客户端调用的“远程Powershell”服务器对象? - How do I create a “Remote Powershell” server object that can be called by clients? 如何在PowerShell中更改对象类型程序集 - How do I Change Object Type Assembly in PowerShell 如何创建实现接口的对象? - How do I create an object that implements an interface? 如何使用通过 a.Net PowerShell object 运行的 PowerShell 脚本获取 windows 注册表属性值? - How do I get windows registry property values using a PowerShell script run through a .Net PowerShell object? 如何在 Mocked 对象的帮助下创建对象? - How do I create object with the help of Mocked object? 如何使用FastMember创建带有子对象的对象的读取器 - How do I Use FastMember to create a reader of an object with child object 如何从HttpPostedFileBase对象创建FileInfo对象? - How do I create a FileInfo object from an HttpPostedFileBase object? 如何创建一个有条件定义类型的对象? - How do I create an object with its type defined conditionally? 如何在C#中创建自定义对象类型类? - How do I create a custom Object type class in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM