Posh-SSH icon indicating copy to clipboard operation
Posh-SSH copied to clipboard

Run POSH-SSH under clean runspace

Open okarpov opened this issue 3 years ago • 1 comments

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.

okarpov avatar Oct 07 '22 18:10 okarpov

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: @.***>

darkoperator avatar Oct 07 '22 19:10 darkoperator