Skip to content

Instantly share code, notes, and snippets.

@hosamn
Forked from dolmen/export-wifi-profiles.cmd
Last active August 20, 2023 08:36
Show Gist options
  • Save hosamn/06f0ba6e4b9bd8bdc535662afd691bec to your computer and use it in GitHub Desktop.
Save hosamn/06f0ba6e4b9bd8bdc535662afd691bec to your computer and use it in GitHub Desktop.
Export all Windows Wifi profiles (SSID, password) in XML
:: Run with full administrator rights
netsh wlan export profile folder=. key=clear
(netsh wlan show profiles) | Select-String "\:(.+)$" | %{$name=$_.Matches.Groups[1].Value.Trim(); $_} | %{(netsh wlan show profile name="$name" key=clear)} | Select-String "Key Content\W+\:(.+)$" | %{$pass=$_.Matches.Groups[1].Value.Trim(); $_} | %{[PSCustomObject]@{ PROFILE_NAME=$name;PASSWORD=$pass }} | Format-Table –Wrap
# based on https://woshub.com/view-saved-wi-fi-passwords-windows/
@echo off
if "%~1"=="" goto :Usage
setlocal
mkdir "%~1" || exit /B 1
netsh wlan export profile "folder=%~1" key=clear >nul
:: Get current code page
for /F "tokens=2 delims=:" %%P in ('chcp') do set CP=%%P
set CP=%CP:~1%
:: Switch to UTF-8
chcp 65001 >nul
(
echo ^<?xml version="1.0" encoding="UTF-8"?^>
echo ^<WLANProfiles^>
for %%P in ("%~1\*") do echo ^<WLANProfile href="%%~nxP"/^>
echo ^</WLANProfiles^>
) > "%~1\index.xml"
:: Restore code page
chcp %CP% >nul
exit /B 0
:Usage
echo usage: %~n0 ^<directory^>
mkdir wifiprof
cd wifiprof
netsh wlan export profile key=clear
dir *.xml |% {
$xml=[xml] (get-content $_)
Write-Host $xml.WLANProfile.SSIDConfig.SSID.name `t $xml.WLANProfile.MSM.Security.sharedKey.keymaterial
}
cd ..
rmdir -recurse wifiprof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment