Posh-SSH icon indicating copy to clipboard operation
Posh-SSH copied to clipboard

Invoke-SSHStreamShellCommand is hanging.

Open SunsparcSolaris opened this issue 1 year ago • 3 comments

Using this module to capture and back up running configs on various HP/Aruba network switches. It runs fine under my account, but when I change over to using the service account that is running it as a scheduled task, the Invoke step hangs indefinitely.

$formattedDate = get-date -format 'yyyyMMdd'
$backupPath = "tftp <IP-ADDRESS>"
$configFile = $switch + ".txt"
$logFile = "C:\TFTP\Logs\"+$switch+"_"+$formattedDate+".log" 
$connection = New-SSHSession -ComputerName $switch -Credential $Cred -AcceptKey:$True -ErrorAction Stop -ConnectionTimeout 120
$session = Get-SSHSession -ComputerName $switch
$stream = New-SSHShellStream -Index $session.sessionid -TerminalName "dumb"
$sshCommand = @"
A
en
<OPERATORUSERNAME>
<OPERATORPASSWORD>
copy startup-config $backupPath $configFile 
Logout
Y
Y
"@
$streamoutput = Invoke-SSHStreamShellCommand -ShellStream $stream -Command $sshCommand -Timeout 10
((($streamoutput -replace '\x1b\[[0-9;]*[a-z]', '').replace("[?25h","")).replace("[?6l[?7h","")).replace("[?25l","") | out-string | Out-File $logFile

Both accounts have the same permissions on the computer running the script and on the switch being backed up. I don't get any sort of output, just hangs.

SunsparcSolaris avatar Sep 20 '24 16:09 SunsparcSolaris

When running as a schedule task I would proba use an iStore for the fingerprints since there is not user folder. But you say it hangs on execution .. in that case to be honest no clue.

darkoperator avatar Sep 20 '24 23:09 darkoperator

When running as a schedule task I would proba use an iStore for the fingerprints since there is not user folder. But you say it hangs on execution .. in that case to be honest no clue.

I set a timeout of 10 seconds on the command and it does indeed time out. It says "returning output collected so far", but it's all blank except for a single line that's not even relevant to the command I'm running.

It's also stopped running fine under my account also, hangs at the first switch in the loop and returns the above.

SunsparcSolaris avatar Oct 08 '24 13:10 SunsparcSolaris

sadly dont have access to that type of gear to test. Most of my coding is against Linux VMs or raspberry Pi’s. Have you looked in to using SFTP instead? https://arubanetworks.com/techdocs/AOS-S/16.11/MCG/KB/content/kb/ena-scp-sft.htm

darkoperator avatar Oct 09 '24 00:10 darkoperator