This project is read-only.

createshell from powershell

Dec 7, 2011 at 8:16 AM

I am trying to query some systems through ssh.

For a few systems it's not allowed to send more commands in one runcommand (eg "cd /tmp ; pwd" or "cd /tmp `n pwd" )

Is it possible to keep a channel open or use the createshell from powershell?

This is my failing test script. I know it's failing because of the channel behaviour.

$scriptName = split-path -leaf $MyInvocation.MyCommand.Definition
$scriptpath = split-path -parent $MyInvocation.MyCommand.Definition

[void][reflection.assembly]::LoadFrom(  "${scriptpath}\..\modules\Renci.SshNet35.dll" )     

$SshClient = New-Object Renci.SshNet.SshClient( $server , 22, $user, $password )
if ($SshClient.IsConnected) {
	$SshCommand = $SshClient.RunCommand("cd /tmp ");
	write-host $SshCommand.Result

	$SshCommand = $SshClient.RunCommand("pwd");
	write-host $SshCommand.Result




Dec 7, 2011 at 11:52 PM


From what I learned so far is that when channel opened, only one command can be executed, after that it has to bo closed since there will be no effect.

It also will have no knowledge of what you done in previouse command execution, like change directory, etc'


I never tried to use Shell object in Powershell, but it should be possible.

Also, if you try that and have some problems or questions, please let me know, since Shell object is not as polished as other parts of the library.