Watch Demo×
×

See NinjaOne in action!

By submitting this form, I accept NinjaOne's privacy policy.

How to Generate a Comprehensive Wireless LAN Report Using PowerShell

Wireless LAN reports are indispensable in the IT industry. The ability to quickly and efficiently understand the state, performance, and potential security vulnerabilities of wireless networks is vital for businesses, large or small. Through a well-structured PowerShell script, one can achieve this seamlessly, providing IT professionals and Managed Service Providers (MSPs) with a the ability to generate a comprehensive wireless LAN report

Background

In an era where network uptime and security are paramount, the ability to generate a Wireless LAN report becomes a necessity. These reports assist IT professionals in monitoring the health of their networks, understanding user behavior, and spotting potential anomalies that might indicate security breaches. For MSPs who manage multiple clients’ networks, these reports provide a tangible way to show work done and insights gained. The provided script is a tool that can be leveraged by IT professionals to automate and simplify this reporting process, harnessing the power of PowerShell scripting.

The Script

#Requires -Version 5.1

<#
.SYNOPSIS
    Saves a Wireless LAN report to a Multi-Line Custom Field.
.DESCRIPTION
    Saves a Wireless LAN report to a Multi-Line Custom Field.
.EXAMPLE
     -CustomField "wlanreport"
    Saves a Wireless LAN report to a Multi-Line Custom Field.
.OUTPUTS
    None
.NOTES
    Minimum OS Architecture Supported: Windows 10, Windows Server 2016
    Release Notes:
    Initial Release
By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https://www.ninjaone.com/terms-of-use.
    Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. 
    Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. 
    Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. 
    Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. 
    Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. 
    Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. 
    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).
#>

[CmdletBinding()]
param (
    [Parameter()]
    [String]
    $CustomField = "wlanreport"
)

process {
    if (-not (Test-IsElevated)) {
        Write-Error -Message "Access Denied. Please run with Administrator privileges."
        exit 1
    }
    if ($env:CustomField) {
        # Use Script Variable and overwrite parameter
        $CustomField = $env:CustomField
    }
    $WLanReportXmlPath = "C:ProgramDataMicrosoftWindowsWlanReportwlan-report-latest.xml"
    # Generate the wlan report
    netsh.exe wlan show wlanreport | Out-Null
    # Check that the xml report exists
    if (-not $(Test-Path -Path $WLanReportXmlPath)) {
        Write-Host "[Error] $WLanReportXmlPath was not created by: netsh.exe wlan show wlanreport"
        exit 1
    }
    # Convert the report from XML to a hash table
    $WLanReport = [xml[]]$(Get-Content -Raw -Path $WLanReportXmlPath) | ConvertFrom-Xml
    # Get the date that the report was generated
    $ReportDate = [DateTime]::ParseExact($WLanReport.WlanReport.ReportInformation.ReportDate -replace 'Z', "yyyy'-'MM'-'dd'T'HH':'mm':'ss", $null)
    # Collect data into one variable
    $Report = if ($WLanReport) {
        # Output the date of the report
        Write-Output "Report Date : $ReportDate"
        # Output the user information
        $WLanReport.WlanReport.UserInformation | Format-Table
        # Output the saved Access Points
        $WLanReport.WlanReport.Profiles.'Wi-Fi'.Keys | ForEach-Object {
            $AccessPointName = $_
            $AccessPointData = [xml[]]$WLanReport.WlanReport.Profiles.'Wi-Fi'."$AccessPointName"
            if ($null -ne $AccessPointData) {
                $AccessPoint = $AccessPointData | ConvertFrom-Xml
                [PSCustomObject]@{
                    AccessPointName  = $AccessPointName
                    Authentication   = $AccessPoint."$AccessPointName".MSM.security.authEncryption.authentication
                    Encryption       = $AccessPoint."$AccessPointName".MSM.security.authEncryption.encryption
                    MacRandomization = $AccessPoint."$AccessPointName".MacRandomization.enableRandomization
                }
            }
        } | Format-Table
        
        # Output the system information
        $WLanReport.WlanReport.SystemInformation.Keys | ForEach-Object {
            $Data = $($WLanReport.WlanReport.SystemInformation."$($_)")
            if ($Data -is "String") {
                Write-Output "$_ : $Data"
            }
        }
        # Output network adapters
        Get-NetAdapter | Format-Table Name, InterfaceDescription, Status, MacAddress, LinkSpeed, MediaType
    }
    else {
        $null
    }

    if ($Report) {
        # Output report to Activity Feed
        $Report | Out-String | Write-Host
        # Save report to multi-line custom field
        Ninja-Property-Set -Name $CustomField -Value $($Report | Out-String)
    }
    else {
        Write-Host "Could not generate wlan report."
        exit 1
    }
    
}
begin {
    function Test-IsElevated {
        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
        $p = New-Object System.Security.Principal.WindowsPrincipal($id)
        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
    }
    function ConvertFrom-Xml {
        param([parameter(Mandatory, ValueFromPipeline)] [System.Xml.XmlNode] $node)
        process {
            if ($node.DocumentElement) { $node = $node.DocumentElement }
            $oht = [ordered] @{}
            $name = $node.Name
            if ($node.FirstChild -is [system.xml.xmltext]) {
                $oht.$name = $node.FirstChild.InnerText
            }
            else {
                $oht.$name = New-Object System.Collections.ArrayList 
                foreach ($child in $node.ChildNodes) {
                    $null = $oht.$name.Add((ConvertFrom-Xml $child))
                }
            }
            $oht
        }
    }
}
end {
    $ScriptVariables = @(
        [PSCustomObject]@{
            name           = "CustomField"
            calculatedName = "customfield"
            required       = $true
            defaultValue   = [PSCustomObject]@{
                type  = "TEXT"
                value = "wlanreport"
            }
            valueType      = "TEXT" # Must be uppercase!
            valueList      = $null
            description    = "A multi-line Custom Field that the report will be saved to."
        }
    )
}

 

Access 300+ scripts in the NinjaOne Dojo

Get Access

Detailed Breakdown

The script begins by checking for the necessary version, which is 5.1, ensuring compatibility. Then, a synopsis, description, and examples are provided, offering a succinct explanation of the script’s purpose.

Parameters are then defined for the script, with the default being “wlanreport.” In the ‘process’ block, the script checks for elevated privileges. Without administrator rights, the script won’t run. It then checks for an environment variable named “CustomField.” If found, it will overwrite the script’s parameter.

The main meat of the script generates the WLAN report through the netsh.exe wlan show wlanreport command and then checks if the report was successfully created. After validation, it converts this XML report into a more readable hash table, extracts useful data like user information, access points, and system information, and then formats them nicely in a table format.

The end block of the script defines some custom functions like Test-IsElevated, which checks if the script is run with elevated rights, and ConvertFrom-Xml, a function to convert XML data.

Potential Use Cases

Imagine Sarah, an IT professional in a medium-sized business. Their office recently experienced some network fluctuations, and Sarah’s task is to diagnose any issues with the WLAN. Using this script, she can quickly generate a detailed WLAN report, uncovering data related to user connections, active access points, and system details, helping her pinpoint the root cause of the issue.

Comparisons

Traditionally, generating a WLAN report would involve manual interventions, using built-in OS tools, third-party software, or even hardware tools. While these methods are still valid, the provided PowerShell script offers automation, speed, and consistency, especially beneficial for MSPs who manage numerous networks and require a standardized approach.

FAQs

  • Can this script be modified to run on older versions of PowerShell? 
    This script specifically requires version 5.1 due to some functionalities it leverages. Attempting to use it with older versions might lead to compatibility issues.
  • What if I want the report saved elsewhere? 
    The script can be modified. You would need to change the $WLanReportXmlPath variable to your desired location.

Implications

While the script helps in generating comprehensive WLAN reports, users must understand its outputs to make meaningful security decisions. Overlooking specific details or misinterpreting the data can lead to security vulnerabilities going unnoticed.

Recommendations

  • Always run the script with the necessary permissions.
  • Ensure your PowerShell version is compatible.
  • Regularly review and interpret the reports generated for effective decision-making.

Final Thoughts

For IT professionals, NinjaOne offers a centralized platform to manage IT infrastructure. Coupling this script with NinjaOne’s capabilities can enhance monitoring, management, and reporting on wireless networks, providing a holistic approach to IT network management. By leveraging tools like the provided PowerShell script, IT professionals can work smarter, not harder, ensuring their networks are always at their best performance.

Next Steps

Building an efficient and effective IT team requires a centralized solution that acts as your core service deliver tool. NinjaOne enables IT teams to monitor, manage, secure, and support all their devices, wherever they are, without the need for complex on-premises infrastructure.

Learn more about NinjaOne Remote Script Deployment, check out a live tour, or start your free trial of the NinjaOne platform.

Categories:

You might also like

NinjaOne Terms & Conditions

By clicking the “I Accept” button below, you indicate your acceptance of the following legal terms as well as our Terms of Use:

  • Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms.
  • Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party.
  • Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library belonging to or under the control of any other software provider.
  • Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations.
  • Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks.
  • Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script.
  • EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).