Public/Network/Get-NearbyWiFiNetworks.ps1

function Get-NearbyWiFiNetworks {
    <#
    .SYNOPSIS
        Retrieves a list of nearby WiFi networks using netsh command.
     
    .DESCRIPTION
        This function executes the netsh wlan show networks command to retrieve
        available WiFi networks and their details including SSID, signal strength,
        and authentication type.
     
    .EXAMPLE
        Get-NearbyWiFiNetworks
        Displays a list of nearby WiFi networks with their details.
     
    .OUTPUTS
        Array of custom objects containing WiFi network details
    #>

    
    try {
        # Execute netsh command to get WiFi networks
        $netshOutput = netsh wlan show networks mode=bssid
        
        # Initialize variables
        $networks = @()
        $currentNetwork = $null
        
        # Parse the output
        foreach ($line in $netshOutput) {
            # Match SSID lines
            if ($line -match "^\s*SSID\s+\d+\s*:\s*(.+)$") {
                # Save previous network if exists
                if ($currentNetwork) {
                    $networks += $currentNetwork
                }
                # Start new network object
                $currentNetwork = [PSCustomObject]@{
                    SSID = $matches[1].Trim()
                    NetworkType = ""
                    Authentication = ""
                    Encryption = ""
                    SignalStrength = ""
                    BSSID = @()
                    Channel = ""
                }
            }
            elseif ($currentNetwork) {
                # Match other network properties
                if ($line -match "Network type\s*:\s*(.+)$") {
                    $currentNetwork.NetworkType = $matches[1].Trim()
                }
                elseif ($line -match "Authentication\s*:\s*(.+)$") {
                    $currentNetwork.Authentication = $matches[1].Trim()
                }
                elseif ($line -match "Encryption\s*:\s*(.+)$") {
                    $currentNetwork.Encryption = $matches[1].Trim()
                }
                elseif ($line -match "Signal\s*:\s*(\d+)%") {
                    $currentNetwork.SignalStrength = $matches[1] + "%"
                }
                elseif ($line -match "BSSID\s+\d+\s*:\s*([a-fA-F0-9:]+)") {
                    $currentNetwork.BSSID += $matches[1].Trim()
                }
                elseif ($line -match "Channel\s*:\s*(\d+)") {
                    $currentNetwork.Channel = $matches[1].Trim()
                }
            }
        }
        
        # Add the last network if exists
        if ($currentNetwork) {
            $networks += $currentNetwork
        }
        
        # Return the results
        return $networks | Sort-Object SignalStrength -Descending
        
    } catch {
        Write-Error "Failed to retrieve WiFi networks: $_"
        return $null
    }
}
New-Alias -Name Get-WiFiNetworksNearby -Value Get-NearbyWiFiNetworks