【问题标题】:SessionStateProxy property is empty at new Runspace object when created using Uri使用 Uri 创建时,新 Runspace 对象的 SessionStateProxy 属性为空
【发布时间】:2016-10-02 13:46:58
【问题描述】:

当我使用 PS 3.0+ 时,我的远程运行空间工作正常,但一旦我使用 PS 2.0 运行我的代码,SessionStateProxy 属性为空(但仅当我尝试创建远程运行空间时。

powershell -version 2

$Uri = New-Object System.Uri("http://WIN-10NL6N4THGJ:5985/wsman")
$connectionInfo = New-Object System.Management.Automation.Runspaces.WSManConnectionInfo($Uri)
$runspace = [runspacefactory]::CreateRunspace($connectionInfo)

$runspace.Open()

$runspace |select *

$runspace.SessionStateProxy

SessionStateProxy 属性应该是 System.Management.Automation.RemoteSessionStateProxy,但它是 $null。有什么线索吗?

【问题讨论】:

  • HI ALIENQuake,如果它在 3.0 中有效,但在 2.0 中无效,则可能是一个错误,请尝试 powershell uservoice windowsserver.uservoice.com/forums/301869-powershell
  • 如果这是一个错误,我怀疑他们会在当前版本为 5.0 时在 2.0 中修复它

标签: c# powershell .net-2.0 runspace


【解决方案1】:

SessionStateProxy 不适用于 PowerShell 2.0 中的远程运行空间。我没有任何文件 atm。备份它,但您可以自己验证它。

本地运行空间:

$r.SessionStateProxy.GetType().FullName
System.Management.Automation.Runspaces.SessionStateProxy

远程运行空间(PS 4.0):

$runspace.SessionStateProxy.GetType().Fullname
System.Management.Automation.RemoteSessionStateProxy

如果您使用 dotPeek 之类的工具查看 System.Management.Automation.dll v.1.0.0 (file Version 6.1.7600.16385)(即 PowerShell 2.0)中的代码,那么您会发现用于本地运行空间的 SessionStateProxy 类,但缺少 RemoteSessionStateProxy。如果您查看System.Management.Automation.dll v.3.0.0 内部,您还会发现RemoteSessionStateProxy internal-class。

解决方案:升级 PowerShell (WMF 3.0 - 5.0)

【讨论】:

  • 我怀疑它是 PS2 不支持的功能,我认为有更多的 c# 经验会弄清楚,感谢有关 System.Management.Automation.dll SessionStateProxy 类的详细信息,它是我需要的确认。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-01-30
  • 2021-07-20
  • 1970-01-01
  • 2019-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多