我成功通过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()
上面的代码只发送一个命令。但是我希望连续执行几个命令而不关闭并重新打开会话。
如果我在第一个命令之后立即添加第二个命令
# execute one command on Cisco switch
$SshCommand = $SshClient.RunCommand('show arp')
$SshCommand = $SshClient.RunCommand('show start')
......脚本挂起,永远不会完成。我做错了什么?
次要相关信息
cmd
input了。它不够可靠。它有时有效,有时不有效。