Run POSH-SSH under clean runspace
How to use it in a clean runspace?
` InitialSessionState iss = InitialSessionState.Create(); SessionStateCmdletEntry getCommand = new SessionStateCmdletEntry( "Get-Command", typeof(Microsoft.PowerShell.Commands.GetCommandCommand), ""); SessionStateCmdletEntry importModule = new SessionStateCmdletEntry( "Import-Module", typeof(Microsoft.PowerShell.Commands.ImportModuleCommand), ""); iss.Commands.Add(getCommand); iss.Commands.Add(importModule);
var runspace = RunspaceFactory.CreateRunspace(iss);
runspace.Open();`
running any POSH-SSH command gives exception: System.Management.Automation.ParseException: The syntax is not supported by this runspace. This can occur if the runspace is in no-language mode.
Never used it in a runspace, I would assume you need to do import-module in the runspace and establish the session from inside the runspaceSent from my iPhoneOn Oct 7, 2022, at 2:20 PM, Oleksandr Karpov @.***> wrote: How to use it in a clean runspace? ```
InitialSessionState iss = InitialSessionState.Create(); SessionStateCmdletEntry getCommand = new SessionStateCmdletEntry( "Get-Command", typeof(Microsoft.PowerShell.Commands.GetCommandCommand), ""); SessionStateCmdletEntry importModule = new SessionStateCmdletEntry( "Import-Module", typeof(Microsoft.PowerShell.Commands.ImportModuleCommand), ""); iss.Commands.Add(getCommand); iss.Commands.Add(importModule); var runspace = RunspaceFactory.CreateRunspace(iss); runspace.Open();
running any POSH-SSH command gives exception: System.Management.Automation.ParseException: The syntax is not supported by this runspace. This can occur if the runspace is in no-language mode.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>