Powershell Invoke-SSHCommand: Exception throws "EndExecute" with argument "1"
I am trying to connect to a Netscaler SDX server via the Posh-SSH module in powershell to find a specific file and then download it. If I connect to the server with putty it works and I can then type in "shell" to open a regular bash console. When I try to connect to powershell I use the following commands.
$hostname = [ip]
$user = [username]
$password = [password]
$secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList
$user, $secureStringPwd
$ssh = New-SSHSession -ComputerName $HostName -Credential $creds
This creates an ssh session that works anyway. Then I use Invoke-SSHCommand.
Invoke-SSHCommand -SessionId ssh.SessionId -Command "shell"
It loads for a while and then throws this exception:
Exception calling "EndExecute" with "1" argument(s): "Command
'shell' has timed out."
At C:\Users\giapsh\Documents\WindowsPowerShell\Modules\posh-ssh\Posh-
SSH.psm1:266 char:25
+ $Output = $_.cmd.EndExecute($_.Async)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SshOperationTimeoutException
I searched this for a search, I found someone with the same problem but didn't answer (used this for German to English translation). I've also tried other things like "ls" for commands, but it returns the same error. Does anyone have an idea what I am doing wrong?
I am using Windows 10 and Powershell 5.1
Hello
Patrick
source to share
I had exactly the same problem. Try SSHStream commands:
PS C:\> $SSHStream = New-SSHShellStream -Index 0
PS C:\> $SSHStream.WriteLine("uname -a")
PS C:\> $SSHStream.read()
Last login: Sat Mar 14 20:02:16 2015 from infidel01.darkoperator.com
[admin@localhost ~]$ uname -a
Linux localhost.localdomain 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22
UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[admin@localhost ~]$
source to share