通过 SSH 和 PowerShell 执行多个命令

nix*_*xda 5 windows ssh powershell cisco

我成功地通过 SSH 连接到 Cisco IE-2000-L 交换机。我使用了Renci SSH.NET库。

入门指南:http : //vwiki.co.uk/SSH_Client_(PowerShell)

我的工作代码是

# Load SSH library (for .NET 4.0 and PowerShell 3)
$DllPath = "D:\temp\Renci.SshNet.dll"
[void][reflection.assembly]::LoadFrom( (Resolve-Path $DllPath) )

# Connect to switch (Cisco IE2000-L) with IP, port, username, password
$SshClient = New-Object Renci.SshNet.SshClient('172.20.91.30', 22, 'admin', 'mypassword')
$SshClient.Connect()

# execute one command on Cisco switch
$SshCommand = $SshClient.RunCommand('show arp')

# show result
$SshCommand.Result 

# close SSH connection
$SshCommand.Dispose()
$SshClient.Disconnect()
$SshClient.Dispose()
Run Code Online (Sandbox Code Playgroud)

我的问题是

上面的代码只发送一个命令。但是我想在不关闭和重新打开会话的情况下连续执行几个命令。

如果我在第一个命令之后添加第二个命令

# execute one command on Cisco switch
$SshCommand = $SshClient.RunCommand('show arp')
$SshCommand = $SshClient.RunCommand('show start')
Run Code Online (Sandbox Code Playgroud)

...脚本挂起并且永远不会完成。我究竟做错了什么?


次要相关信息