04-07-2021 04:04 PM
Hello,
I search how to configure port (example: enable/disable) on VSP 8400 with Powershell
No probleme on X440 (EXOS) with SSHCommand but don’t work on VSP
The connection seems good but the orders (Invoke-SSHCommand) are blocked for few seconds, and after connection lost
Can you hlep me ?
Thanks
Solved! Go to Solution.
04-08-2021 08:41 AM
Juste for information, it’s perfectible but it’s working like this:
#install module
#Install-Module -Name Posh-SSH -force
#create username/pw
$userName = "admin"
$password = "password"
#create $cred as secure string using $username and $password
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
#create ssh session to server that fired alert using $cred
$sessionSSH = New-SSHSession -ComputerName "switch_IP" -Credential $cred -AcceptKey
#set stream
$stream = $sessionSSH.session.CreateShellStream("PS-SSH", 0, 0, 0, 0, 1000)
#invokes stream to run command as sudo. gets pw from $secstr
$result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -command "enable" -ExpectString "10" -SecureAction $secstr
$result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -command "configure terminal" -ExpectString "10" -SecureAction $secstr
$result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -command "interface gigabitEthernet 3/15" -ExpectString "10" -SecureAction $secstr
$result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -command "shutdown" -ExpectString "10" -SecureAction $secstr
$stream.Read()
$id_session = Get-SSHSession
Remove-SSHSession $id_session
04-08-2021 11:50 AM
thanks for sharing
04-08-2021 08:41 AM
Juste for information, it’s perfectible but it’s working like this:
#install module
#Install-Module -Name Posh-SSH -force
#create username/pw
$userName = "admin"
$password = "password"
#create $cred as secure string using $username and $password
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
#create ssh session to server that fired alert using $cred
$sessionSSH = New-SSHSession -ComputerName "switch_IP" -Credential $cred -AcceptKey
#set stream
$stream = $sessionSSH.session.CreateShellStream("PS-SSH", 0, 0, 0, 0, 1000)
#invokes stream to run command as sudo. gets pw from $secstr
$result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -command "enable" -ExpectString "10" -SecureAction $secstr
$result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -command "configure terminal" -ExpectString "10" -SecureAction $secstr
$result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -command "interface gigabitEthernet 3/15" -ExpectString "10" -SecureAction $secstr
$result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -command "shutdown" -ExpectString "10" -SecureAction $secstr
$stream.Read()
$id_session = Get-SSHSession
Remove-SSHSession $id_session
04-08-2021 07:29 AM
Hello,
ok I understand, I will test
Thank you for your prompt response.
have a good day.
04-07-2021 06:20 PM
I never used this Posh-SSH module, but reading its documentation here https://www.powershellmagazine.com/2014/07/03/posh-ssh-open-source-ssh-powershell-module/
it seems to me that Invoke-SSHCommand is sending the commands in a dedicated SSH channel within the SSH session; this is how SSH emulates the older rsh. But this mode will not work with VOSS. VOSS SSH server requires an interactive shell to be run inside the SSH channel.
So I think you will need to use the $session.Session.CreateShellStream approach from the same link above.