Renci SSH.NET - script hangs indefinitly

1.5k Views Asked by At

Here is the code - hangs after last command:

$DllPath = "Q:\A_FILES\PowerSHell\SSH_NET_for_powershell\Renci.SshNet_Binary\Renci.SshNet.dll"
[void][reflection.assembly]::LoadFrom( (Resolve-Path $DllPath) )
$SshClient = New-Object Renci.SshNet.SshClient('199.12.13.44', 22, 'userid', 'password')
$SshClient.Connect()
Get-Process | Out-File -FilePath D:\Powershell\SAN_NAP01_TEST.txt -Encoding ASCII
$SshCommand = $SshClient.RunCommand('statistics show-periodic')

The command issued via SSH above - STATISTICS show-periodic - when manually issued to an SSH session into the Netapp Storage SAN - starts displaying data and runs forever - you are not given a prompt again - you must manually issue CTRL-C to exit this command and then you receive the CLI prompt in the SSH session to issue another desired command. I assume this is why the powerscript hangs - because the command does not go back to a prompt - without a CTRL-C issued.

I would like to issue $SshCommand = $SshClient.RunCommand('CTRL-C') following the above last command (after a desired sleep time) - but the powershell script does not get control back.

Wondering if their is any way to get control back after the statistics... command and then be able to issue the CTRL-C command into the SSH session after a desired time interval.

1

There are 1 best solutions below

0
On

are you connecting to a Netapp server?

If that's the case you could consider using the -iterations parameter in your command, so your statistics command returns.

$SshCommand = $SshClient.RunCommand('statistics show-periodic -iterations 5')