Reputation: 282
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?
Upvotes: 2
Views: 298
Reputation: 54941
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)
Upvotes: 2