this is my code:
@(
' ', #for "Press any key to continue"
'show mac-address'
) | plink <ip> -P 22 -ssh -v -l admin -pw pwd -batch
Read-Host -Prompt “Press Enter to exit”
sometimes i get this output:
←[1;13r←[1;1HSession sent command exit status 0
Main session channel closed
All channels closed
and sometimes i get this output:
Remote side unexpectedly closed network connection
FATAL ERROR: Remote side unexpectedly closed network connection
If i write the plink command without Pipe:
plink <ip> -P 22 -ssh -v -l admin -pw pwd -batch
It works. But i need it automated
I happen to have an Aruba switch and found that specifying non-interactive SSH with
-batch, or commands with-m, just causes the switch to disconnect your session like you're seeing. Maybe there's a setting to allow it?I found this works pretty well, using more of a .net approach due to issues with
Start-Processredirection. This opensplinkin a separate process, and sends commands to its stdin:You may have to play around with the commands a bit, but I found plink was pretty generous with how quickly input gets thrown at it
I did notice if the plink process is waiting (ssh session still connected), then
ReadToEnd()will wait forever. Maybe it can be replaced with aReadLine()loop, but it can be hard to tell when it's done.