cancel
Showing results for 
Search instead for 
Did you mean: 

Powershell VSP enable/disable port

Powershell VSP enable/disable port

matth59del
New Contributor II

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

1 ACCEPTED SOLUTION

matth59del
New Contributor II

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

View solution in original post

4 REPLIES 4

PeterK
Contributor III

thanks for sharing

matth59del
New Contributor II

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

matth59del
New Contributor II

Hello,

ok I understand, I will test
Thank you for your prompt response.
have a good day.

Ludovico_Steven
Extreme Employee

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.

GTM-P2G8KFN