Forum Discussion
Retrieving information from multiple Access Points via PowerShell
Hello everyone!
I am doing a WiFi site survey and I would need to retrieve some information from all the Access Points installed in our school (around 136). I wonder if it would be feasible to write a Powershell script which should be able to:
- Connect to all the Aerohive Access Points via SSH (from a list of IP addresses)
- Run a specific command for each AP (e.g. "show interface")
- Export the results of that command to a txt/html file
My purpose is getting all the different MAC addresses used by each AP and listing them on a txt/html file.
I have been told that I could use a Python module (Aeromiko) to extract data from the Access Points but I am not familiar with the Python language.
Could you please advise on this?
Thank you in advance!
9 Replies
- Erick A. Moreno R.Iron Contributor
fstorer I wrote this, I think it covers what you are trying to accomplish.
Let me know how it goes.
<# .SYNOPSIS Create ssh session and run a command from a list of hosts .DESCRIPTION .NOTES Author: Erick A. Moreno Email: emoreno@request-script.com Date: 12 Jan 2020 PowerShell: v3 .References #https://www.powershellgallery.com/packages/Posh-SSH/2.1 #Install Posh-Ssh Module to use the corresponding cmdlets #requested: https://techcommunity.microsoft.com/t5/forums/replypage/board-id/WindowsPowerShell/message-id/1011 #> $WorkingDir = "C:\Users\erick\Desktop\LogsFolder" $ScriptTime = Get-Date -UFormat "%m%d%Y-%H%M" $Credentials = Get-Credential $APList = Import-Csv "$WorkingDir\APIPs.csv" $Output = @() Foreach($AP in $APList) { Write-Host "Working on AP: $($AP.Name)" -ForegroundColor Cyan $Command = $AP.Command $Results = $null $session = New-SSHSession -ComputerName $AP.IP -Credential $Credentials -AcceptKey If(![string]::IsNullOrEmpty($($session))) { $Results = Invoke-SSHCommand -Index $session.SessionId -Command $Command $Properties = [Ordered]@{ APName = $AP.Name APIPAddress = $AP.IP Command = $Command Results = $($Results.Output) -join ";" #Adapt this depending on the type of output that you expect } $Output += New-Object PSObject -Property $Properties Remove-SSHSession -SessionId $session.SessionId } Else { Write-Host "Unable to stablish ssh session with host: $($AP.Name) / $($AP.IP)" -ForegroundColor Yellow } } $Output | Export-Csv "$WorkingDir\APsReport_$Scripttime.csv" -NoTypeInformation -Encoding UTF8
- fstorerBrass Contributor
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 : 255For 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?
- Erick A. Moreno R.Iron Contributor
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