Thursday, November 10, 2016

Powershell script for retrieving stored wireless passwords

On W10 it is trivially easy to retrieve stored passwords for wireless netwerk. I cobled the following script together to store the passwords before a migration. Note that this assumes an English version of Windows, on some machines you may need to modify the 'User Profiles' and 'Key Content' strings.

Run the following to find the string on your system;



And



And the full script:

$output = netsh wlan show profiles
$from = $output.IndexOf("User profiles")

$output = $output[($from+2)..($output.length-2)]

$results = @()

foreach ($entry in $output) {
  $networkName = ($entry.Split(':')[1]).Trim()

  $networkInfo = netsh wlan show profile name=$networkName key=clear

  foreach($infoLine in $networkInfo) {
    if ($infoLine.Trim().StartsWith("Key Content")){
      $password = ($infoLine.Split(':')[1]).Trim()

      if ($password -ne "Absent"){
        Write-Host Processing $networkName
        $networkProperties = @{
          Name = $networkName
          Password = $password
        }
                      $results += (New-Object PSObject -Property $networkProperties)
      }
    }
  }
}

$results | ft Name,Password


Rating