Export all SSID/Network Profiles with Passwords

Export all SSID/Network Profiles with Passwords

  •  
  •  
  •  
  •  
  •  
  •  

After I re-posted a quick script to export all of the Windows Vault credentials, one of my good friends, Aaron Steele, threw down the gauntlet:

Export all SSID/Network Profiles with Passwords

To that, I say …

Export all SSID/Network Profiles with Passwords

Yes, it’s rushed and messy (and has a couple of quirks), but gauntlets have to be responded to quickly and all.

param (
[switch]$AllProfiles,
[string]$Output = (Get-Date -Format yyyy-MM-dd)+"_AllWifiPasswords.csv",
[string]$WifiProfile,
[switch]$ShowProfiles
)

# Check if Elevated
$wid = [system.security.principal.windowsidentity]::GetCurrent()
$prp = New-Object System.Security.Principal.WindowsPrincipal($wid)
$adm = [System.Security.Principal.WindowsBuiltInRole]::Administrator
if ($prp.IsInRole($adm))
{
Write-Host -ForegroundColor Green "Elevated PowerShell session detected. Continuing."
}
else
{
Write-Host -ForegroundColor Red "This application/script must be run in an elevated PowerShell window. Please launch an elevated session and try again."
Break
}

function ChooseProfile
{
# Get Profiles and build menu
[array]$AllWifiSSIDs = (netsh.exe wlan show profiles)
[array]$AllWifiSSIDs = $AllWifiSSIDs | % { ($_.Split(":")[1]) }

$ProfileMenu = @{ }
$Choice = $null
Write-Host -Fore Yellow "Available WLAN Profiles"
For ($i = 1; $i -le $AllWifiSSIDs.Count; $i++)
{
Write-Host "$i. $($AllWifiSSIDs[$i - 1])"
$ProfileMenu.Add($i, ($AllWifiSSIDs[$i - 1]))
}

If (!($WifiProfile))
{
[int]$ProfileSelection = Read-Host "Enter SSID/Network profile number"
$ProfileName = $ProfileMenu.Item($ProfileSelection)
}

Write-Host -NoNewline "Profile selected: "; Write-Host -ForegroundColor Green "$($ProfileName)"

$Choice = Read-Host "Correct? [Y/N]"
[array]$script:WifiProfile = $ProfileName

while ($Choice -ne "Y")
{
If ($WifiProfile) { Remove-Variable WifiProfile -ea SilentlyContinue }
ChooseProfile
}
}

If (!$WiFiProfile -and !$AllProfiles)
{
ChooseProfile
}

If ($WiFiProfile) { [array]$AllSSIDs = $WiFiProfile }
If ($AllProfiles)
{
[array]$AllSSIDs = (netsh.exe wlan show profiles)
[array]$AllSSIDs = $AllSSIDs | % { ($_.Split(":")[1]) }
}

$global:AllSSIDPasswords = @()
foreach ($obj in $AllSSIDs)
{
if ($obj -ne $null -and $obj -ne " " -and $obj -ne "")
{
$KeyContent = $null
$PasswordValue = $null
$objProfileName = $obj.Trim()
$Temp = (netsh.exe wlan show profiles name="$($objProfileName)" key=clear)
$KeyContent = $Temp | Select-String -Pattern "Key Content"
If ($KeyContent) { $PasswordValue = $KeyContent.ToString().Split(":")[1].Trim() }
If (!($PasswordValue)) { $PasswordValue = "Not present" }
$Global:Record = [PSCustomObject]@{
ProfileName = "$($objProfileName)"
Password = "$($PasswordValue)"
}
Try { $global:AllSSIDPasswords += $global:Record }
Catch { }
}
}
$AllSSIDPasswords | Export-Csv $Output -NoTypeInformation -Force
Write-Host "All SSID/Profiles and corresponding passwords have been exported if available. The results are available in this session with the `$AllSSIDPasswords, which you can pipe to destinations such as console, Out-GridView, or Export-Csv."

If ($WiFiProfile -and $PasswordValue)
{
Write-Host -NoNewLine "Profile/SSID: "
Write-Host -ForegroundColor Green $WifiProfile.Trim()
Write-Host -NoNewline " Password: "
Write-Host -ForegroundColor Green "$($PasswordValue)"
}

If you dig through, you’ll notice that we’re doing a bunch of string manipulation on netsh output.  It’s been 15 years since PowerShell’s debut, and we still don’t have a suitable replacement for that command.  I’m just the messenger.

At any rate, the script comes laden with four whole parameters:

  • AllProfiles – dumps all Wifi /SSID Profiles and associated passwords
  • Output – I hope I don’t need to explain this one
  • WifiProfile – Export password for a specific profile
  • ShowProfiles – Display a list of all profiles to choose from (which will also happen if you don’t enter any other details)

You can copy/paste it from here, or you can pop over to the PowerShell Gallery to pick it up. 😉

Published by Aaron Guilmette

Helping companies conquer inferior technology since 1997. I spend my time developing and implementing technology solutions so people can spend less time with technology. Specialties: Active Directory and Exchange consulting and deployment, Virtualization, Disaster Recovery, Office 365, datacenter migration/consolidation, cheese.

Leave a Reply

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