Monitoring with PowerShell: Monitoring WLAN reports

This is a bit of a short one, but I’m trying to get back to two blogs a week slowly, today we’re talking about a pretty cool feature that Microsoft has made for Windows, but doesn’t get the attention it deserves. When you’re troubleshooting WLAN issues there’s a lot of locations to investigate – If users are reporting dropped networks you’ll have to check the event logs, if users are reporting authentication issues you’ll have to check the network settings.

This all gets really confusing because there’s just so many logs and so many options. Microsoft simplified this by creating the WLAN network reporting functionality. You can generate this report by executing the following command:

netsh wlan show wlanreport 

This generates a report in “C:\ProgramData\Microsoft\Windows\WlanReport\wlan-report-latest.html” which gives you a pretty cool overview of all events that happened on the wireless network. The only downside is that this report isn’t automatically generated so with intermittent issues it’s a bit harder to troubleshoot. For those cases, I’ve created the following monitoring script.

The Script

The script tries to generate a report each time it runs. If it can’t write the script and it won’t find a file that is newer than 4 hours, it’ll generate an alert that the reports aren’t there. You’ll still have to manually check the report unfortunately, as it’s not a parsable report due to the HTML magic in there.

try {
    $WLANReport = netsh wlan show wlanreport 
    $WriteTime = Get-Item "$($ENV:Systemdrive)\ProgramData\Microsoft\Windows\WlanReport\wlan-report-latest.html" | Where-Object { $_.lastWriteTime -gt (get-date).AddHours(-4) }
    if(!$WriteTime){ throw "No report found in last 4 hours." }
    write-host"Healthy - Latest report can be found at $($ENV:Systemdrive)\ProgramData\Microsoft\Windows\WlanReport\wlan-report-latest.html"
}
catch {
    write-host "Could not find latest report: $($_.Exception.Message)"
    exit 1
}

That’s all for today. As always, Happy PowerShelling 🙂

2 Comments

  1. Chris Thomas November 24, 2021 at 4:18 am

    This report actually holds a few days’ worth of data. This is a good concept for keeping it fresh though. Were you by chance reading my script share post on Ninja?

    1. Kelvin Tegelaar November 27, 2021 at 12:58 pm

      I haven’t seen your post, to be honest I don’t visit the ninja community often. 🙂 We did talk a lot about the usages of this tool some months ago in MSPGeek so I figured it would be worth a blog. Glad you like it!

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.