Recently I’ve changed my old laptop (Toshiba Z30) to Surface Pro LTE. I needed to migrate the data to the new laptop including the WiFi list with passwords.
Of course one can click through the WiFi control panel and write down all the passwords, but I don’t recommend that as there’s an easier way to accomplish the goal using PowerShell :)
Below there’s a function that is based on a script I found in Google. The function returns a hash with a network name and it’s password:
function Get-WifiCredentials() {
mkdir wifi
cd wifi
netsh wlan export profile key=clear
$credentials = @{}
Get-ChildItem *.xml | % {
$xml=[xml] (Get-Content $_)
$name = $xml.WLANProfile.SSIDConfig.SSID.name
$key = $xml.WLANProfile.MSM.Security.sharedKey.keymaterial
if (![String]::IsNullOrWhitespace($key))
{
$credentials.Add($name, $key)
}
}
cd ..
rmdir -recurse wifi
return $credentials
}
Leave a Comment