Forum Discussion
Retrieving information from multiple Access Points via PowerShell
Thank you so much for your kind reply and apologies for replying so late, I was off for a few weeks... I have tried your script, I am able to start a SSH session with the AP (I can see the SessionID and that the connection is working), but the output of the commands is always empty. When I try to run the single commands, I got something like this:
Host : 192.168.x.x
Output : {}
ExitStatus : 255
For example, I tried to run the following commands:
Invoke-SSHCommand -SessionId 0 -Command "show interface"
Invoke-SSHCommand -SessionId 0 -Command "show ssid"
In both cases, I got the results above.
I see that the ExitStatus is returning a 255 error code, but I can't understand why.
When running those commands on the AP, I get tables with multiple columns (Name/MAC addr/Mode/State/Chan/VLAN/Radio/Hive/SSID) and a list of MAC addresses/SSIDs.
Any suggestions?
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
- fstorerFeb 27, 2020Brass Contributor
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:
$Credentials = Get-Credential$session = New-SSHSession -ComputerName x.x.x.x -Credential $Credentials -AcceptKey$SSHStream = New-SSHShellStream -SessionId 0$SSHStream.WriteLine("show interface")$SSHStream.read()I hope this may be of some help!Thanks again for your help, I really appreciate that! And thanks to the creator of "Posh-SSH" module!- 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?