Skip to content

Instantly share code, notes, and snippets.

@azurekid
Last active May 9, 2025 08:24
Show Gist options
  • Select an option

  • Save azurekid/96882bb1b604bb2cb660a786172802d7 to your computer and use it in GitHub Desktop.

Select an option

Save azurekid/96882bb1b604bb2cb660a786172802d7 to your computer and use it in GitHub Desktop.
This function can be used to quickly retrieve all stored WiFi passwords on a Windows device
<#
.SYNOPSIS
Retrieves stored WiFi profiles and their associated passwords from the local computer.
.DESCRIPTION
This function uses netsh commands to extract all saved WiFi profiles and their details including passwords (if available), authentication methods, and connection modes. It processes profiles in parallel for improved performance.
.OUTPUTS
System.Object[]
Returns an array of custom objects containing the following properties:
- ProfileName: The name of the WiFi profile
- Password: The network key/password (if available and retrievable)
- Authentication: The authentication method used (WPA2, WPA, etc.)
- ConnectionMode: The connection mode of the profile
.EXAMPLE
Get-WifiProfiles
.EXAMPLE
Get-WifiProfiles | Export-Csv -Path ".\wifi-profiles.csv" -NoTypeInformation
.NOTES
Requires:
- Administrative privileges
- Windows OS with WLAN services
- PowerShell 7+ for parallel processing
Author: Rogier Dijkman (azurekid)
Last Modified: 2025-05-08
Version: 1.0
.LINK
https://docs.microsoft.com/en-us/windows/win32/nativewifi/about-the-native-wifi-api
#>
Function Get-WifiProfiles {
try {
# Get all profiles in one call and parse more efficiently with regex
$profilesOutput = (netsh wlan show profiles) -join "`n"
$profileMatches = [regex]::Matches($profilesOutput, 'All User Profile\s+:\s+(.+)')
$results = $profileMatches | ForEach-Object {
$wifiprofile = $_.Groups[1].Value.Trim()
$detailsOutput = (netsh wlan show profile name="$wifiprofile" key=clear) -join "`n"
# Extract password with regex
$passwordMatch = [regex]::Match($detailsOutput, 'Key Content\s+:\s+(.+)')
$password = if ($passwordMatch.Success) { $passwordMatch.Groups[1].Value.Trim() } else { $null }
$ssidMatch = [regex]::Match($detailsOutput, 'SSID name\s+:\s+"?([^"]+)"?')
$authMatch = [regex]::Match($detailsOutput, 'Authentication\s+:\s+(.+)')
$encryptMatch = [regex]::Match($detailsOutput, 'Cipher\s+:\s+(.+)')
$connectionMatch = [regex]::Match($detailsOutput, 'Connection mode\s+:\s+(.+)')
# Check if currently connected
$interfaces = netsh wlan show interfaces
[PSCustomObject]@{
ProfileName = $wifiprofile
Password = $password
Authentication = if ($authMatch.Success) { $authMatch.Groups[1].Value.Trim() } else { "Unknown" }
ConnectionMode = if ($connectionMatch.Success) { $connectionMatch.Groups[1].Value.Trim() } else { "Unknown" }
}
}
return $results
}
catch {
Write-Error "Failed to retrieve WiFi profiles: $_"
}
}
Get-WifiProfiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment