2

My remote runspaces works fine when I'm using PS 3.0+ but as soon as I'm running my code using PS 2.0, SessionStateProxy property is null (but only when I try to create remote runspace.

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 property should be System.Management.Automation.RemoteSessionStateProxy but it is $null. Any clue?

Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
ALIENQuake
  • 520
  • 3
  • 12
  • 28
  • HI ALIENQuake, if it works in 3.0, but not in 2.0 then it is probably a bug, try the powershell uservoice https://windowsserver.uservoice.com/forums/301869-powershell – Neossian Jun 06 '16 at 16:11
  • If it's a bug I doubt they will fix it in 2.0 when the current Version is 5.0 – Frode F. Jun 07 '16 at 08:13

1 Answers1

2

SessionStateProxy isn't available for remote runspaces in PowerShell 2.0. I don't have any documentation atm. to back it up, but you can verify it yourself.

Local runspace:

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

Remote runspace (PS 4.0):

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

If you use something like dotPeek to view the code inside the System.Management.Automation.dll v.1.0.0 (file Version 6.1.7600.16385) which is PowerShell 2.0, then you will find the SessionStateProxy class that's used for local runspaces, but RemoteSessionStateProxy is missing. If you look inside System.Management.Automation.dll v.3.0.0 then you will also find the RemoteSessionStateProxy internal-class.

Solution: Upgrade PowerShell (WMF 3.0 - 5.0)

Frode F.
  • 52,376
  • 9
  • 98
  • 114
  • I suspect that it's a unsupported feature for PS2 and I'm counted for some more experience with c# will figure it out, thanks for detailed information about System.Management.Automation.dll SessionStateProxy class, it's the confirmation which I needed. – ALIENQuake Jun 08 '16 at 16:59