简体   繁体   中英

Powershell Invoke-SSHCommand: Exception calling “EndExecute” with “1” argument(s)

I'm trying to connect to a Netscaler SDX server via the Posh-SSH module in powershell, to search for a specific file and then download it. If i connect to the server with putty it works and I can then enter "shell" to open a normal bash console. When i try to connect with powershell i use 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 a ssh session which still seams to work. Next I use Invoke-SSHCommand.

Invoke-SSHCommand -SessionId ssh.SessionId -Command "shell"

It loads for a while and then throws out 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 googled for it, I only found someone with the same problem but no answer (used that to translate from german to english). I also tried other things like "ls" for commands but the same error returned. Does someone have an Idea what I am doing wrong?

I'm using Windows 10 and Powershell 5.1

Regards

Patrick

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 ~]$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM