We’ve all been there, wireless passwords tend get lost.
There are several tools to retrieve the missing information, but I strongly believe that the less stuff you download from the web, the safer you are. Here are three different solutions to retrieve a locally stored password.
PowerShell
If you’re running Windows 7 or later you will be able to retrieve (and format) the password using the line of code below. Make sure to run the console as Administrator:
(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 -AutoSize
Command Prompt
If you’re running older versions of Windows you can use the same command and scroll through the information manually. Make sure to run the console as Administrator:
netsh wlan show profiles "NETWORK-SSID" key=clear
Third-party software
If you don’t mind downloading third party software I’d recommend NirSoft’s WirelessKeyView.
It can be downloaded from the NirSoft website.
not working on Win7 running powershell as Admin, this is the error i receive:
Cannot index into a null array.
At line:1 char:82
+ (netsh wlan show profiles) | Select-String "\:(.+)$" | %{$name=$_.Matches.Groups[ <<<< 1].Value.Trim(); $_} | %{(nets
h wlan show profile name="$name" key=clear)} | Select-String "Key Content\W+\:(.+)$" | %{$pass=$_.Matches.Groups[1].Va
lue.Trim(); $_} | %{[PSCustomObject]@{ PROFILE_NAME=$name;PASSWORD=$pass }} | Format-Table -AutoSize
+ CategoryInfo : InvalidOperation: (1:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Hi Will,
Which version of PowerShell are you running?
You can check by writing $PSVersionTable
Best regards
This is the result with the test machine
Name Value
—- —–
CLRVersion 2.0.50727.5485
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1
powershell 2.0 doesn't cast as an array before attempting to index, this works:
(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 -AutoSize
but PSCustomObject isnt 2.0 so no pretty table, ill have to try to figure that out
Thanks man, the script came in handy. Saved me having to write a powershell script and figure out regex all over again.