Powershell Invoke-SSHCommand:使用“1"参数调用“EndExecute"异常 [英] Powershell Invoke-SSHCommand: Exception calling “EndExecute” with “1” argument(s)
问题描述
我正在尝试通过 powershell 中的 Posh-SSH 模块连接到 Netscaler SDX 服务器,以搜索特定文件,然后下载它.如果我用腻子连接到服务器,它就可以工作,然后我可以输入shell"来打开一个普通的 bash 控制台.当我尝试使用 powershell 连接时,我使用以下命令.
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
这会创建一个仍然可以正常工作的 ssh 会话.接下来我使用 Invoke-SSHCommand.
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
我用谷歌搜索,我只找到了一个有同样问题但没有答案的人(用它来从德语翻译成英语).我还尝试了其他命令,例如ls",但返回了相同的错误.有人知道我做错了什么吗?
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?
我使用的是 Windows 10 和 Powershell 5.1
I'm using Windows 10 and Powershell 5.1
问候
帕特里克
推荐答案
我遇到了完全相同的问题.尝试 SSHStream 命令:
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 ~]$
这篇关于Powershell Invoke-SSHCommand:使用“1"参数调用“EndExecute"异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!