PSScripts/Get-WiFiProfiles.ps1

29 lines
848 B
PowerShell
Raw Normal View History

2023-12-18 18:01:27 +00:00
# Gets all the WiFi profiles stored on a PC, including passwords
$wifi = $(netsh.exe wlan show profiles)
if ($wifi -match "There is no wireless interface on the system."){
Write-Output $wifi
exit
}
$SSIDs = ($wifi | Select-string -pattern "\w*All User Profile.*: (.*)" -allmatches).Matches | ForEach-Object {$_.Groups[1].Value}
$SSIDsPassphrases =
foreach ($SSID in $SSIDs){
try {
$passphrase = ($(netsh.exe wlan show profiles name="$SSID" key=clear) |
Select-String -Pattern ".*Key Content.*:(.*)" -AllMatches).Matches |
ForEach-Object {$_.Groups[1].Value}
}
catch{
$passphrase = "N/A"
}
[PSCustomObject]@{
SSID = $SSID
Passphrase = $passphrase
}
}
Write-Output "The WiFi profiles on this System are:" $SSIDsPassphrases