Forum Discussion
Retrieving information from multiple Access Points via PowerShell
fstorer don't worry I understand, I'm glad to help.
About the error, have you confirmed that the network is ok? I mean the session was established correctly but there could be a timeout so please increase the timeout option to see how it behaves. Could you try with a single command like help just to see if it is taking the command string correctly?
I don't think the format is a problem is should display something as I said in my comment in the script we may need to work on formatting that table.
Regards
I was able to solve my problem thanks to this article: https://github.com/darkoperator/Posh-SSH/issues/146
Using New-SSHShellStream instead of Invoke-SSHCommand returned all the results I wanted.
I need to tweak the final script, but these are the commands I used:
- Erick A. Moreno R.Feb 27, 2020Iron Contributor
fstorer Awesome, thanks for the update. So we need to push commands that way whenever the command has params, good to know.
Regards
Erick
- fstorerMar 02, 2020Brass Contributor
Dear Erick A. Moreno R.
Unfortunately, I am still having issues with the output...
I want to send the output of the "$SSHStream.read()" to a txt file, but when I run the command:
Out-File -FilePath ".\APInterfaces.txt" -InputObject $SSHStream.read()I got a blank txt file.Any suggestions?- Erick A. Moreno R.Mar 02, 2020Iron Contributor
fstorer Hello, you got that as once you run the read from the stream you reset the variable to no data.
I've tested this saving the read output to a new Variable and it is working for me, please test it and let me know the outcome.
$session = New-SSHSession -ComputerName $AP.IP -Credential $Credentials -AcceptKey $SSHStream = New-SSHShellStream -SessionId $session.SessionId $SSHStream.WriteLine("show interface") $OutputVar = $null $OutputVar = $($SSHStream.read()) $OutputVar $OutputVar | Out-File -FilePath "$WorkingDir\APInterfaces.txt" -Encoding utf8Regards
Erick Moreno