What is SessionStateProxy and how can I access it in the scenarios
below? In particular I am interested in the instance provided by
default runspace and the way 2 is more practically interesting to me,
as far as I am trying to use it for a custom host.
[OUTPUT]Code:Set-StrictMode -Version 2 Write-Host "This does not fail, but SessionStateProxy properties are null" $rs = [Management.Automation.Runspaces.Runspace]::DefaultRunspace $ss = $rs.SessionStateProxy $ss.InvokeCommand -eq $null $ss.Path -eq $null Write-Host "This way simply fails" Add-Type @' using System.Management.Automation.Runspaces; public class Class1 { public static object GetInvokeCommand() { Runspace rs = Runspace.DefaultRunspace; return rs.SessionStateProxy.InvokeCommand; } public static object GetPath() { Runspace rs = Runspace.DefaultRunspace; return rs.SessionStateProxy.Path; } } '@ try { [Class1]::GetInvokeCommand() } catch { Write-Warning $_ } try { [Class1]::GetPath() } catch { Write-Warning $_ }
This does not fail, but SessionStateProxy properties are null
True
True
This way simply fails
WARNING: Exception calling "GetInvokeCommand" with "0" argument(s): "A
pipeline is already executing.
Concurrent SessionStateProxy method call is not allowed."
WARNING: Exception calling "GetPath" with "0" argument(s): "A pipeline
is already executing.
Concurrent SessionStateProxy method call is not allowed."
[/OUTPUT]


