Get Known Wifi Networks Passwords PowerShell

Get Known Wifi Networks Passwords PowerShell

Hello,

Have ever wanted to know the password you type on your laptop to connect to some wifi networks to be abe to connect your new one or your phone to it ? o you remember all the passwords of all your wifi networks you connected to with your laptop ? Probably not, but Windows do, and we can ask him.

You can get it with:

netsh wlan show profiles

This will display all the known wifi networks. You can then, for each of them, request the password:

netsh wlan show profile name=MyWifi key=clear

This will display detailed information about the network name “MyWifi”, including the security key.

If you want a more readable format, we need to use PowerShell:

netsh wlan show profile | Select-Object -Skip 3| Where-Object -FilterScript {($_ -like '*:*')} | ForEach-Object -Process {
    $NetworkName = $_.Split(':')[-1].trim()
    $PasswordDetection = $(netsh wlan show profile name =$NetworkName key=clear) | Where-Object -FilterScript {($_ -like '*contenu de la clé*') -or ($_ -like '*key content*')}

    New-Object -TypeName PSObject -Property @{
        NetworkName = $NetworkName
        Password = if($PasswordDetection){$PasswordDetection.Split(':')[-1].Trim()}else{'Unknown'}
    } -ErrorAction SilentlyContinue
}

The netsh tool is sensitive about the language of the underlaying operating system, my code will work for French or English OS.

Get Known Wifi Networks Passwords PowerShell - Exemple

Get Known Wifi Networks Passwords PowerShell – Exemple

You’ll have one object per known wifi network.

Add the function to your PowerShell profile

Now, to get it very convenient, let’s put in in a function, and add it to our $profile:

Function Get-WifiPassword {
    netsh wlan show profile | Select-Object -Skip 3| Where-Object -FilterScript {($_ -like '*:*')} | ForEach-Object -Process {
        $NetworkName = $_.Split(':')[-1].trim()
        $PasswordDetection = $(netsh wlan show profile name =$NetworkName key=clear) | Where-Object -FilterScript {($_ -like '*contenu de la clé*') -or ($_ -like '*keu content*')}

        New-Object -TypeName PSObject -Property @{
            NetworkName = $NetworkName
            Password = if($PasswordDetection){$PasswordDetection.Split(':')[-1].Trim()}else{'Unknown'}
        } -ErrorAction SilentlyContinue
    } 
}

And paste it in:

ise $PROFILE.CurrentUserAllHosts

If you don’t have a profile yet, you can create one with:

New-Item -Path $profile.CurrentUserAllHosts -ItemType file -Force | Out-Null

Once you done that, you can call the function whenever you want, it will be available.

5 thoughts on “Get Known Wifi Networks Passwords PowerShell

  1. Pingback: ICYMI: PowerShell Week of 9-November-2018 | PowerShell.org

  2. Very useful, thanks for this. On a sidenote: there’s a typo in the script, it sais keu instead of key in the where-object filterscript. (and then the result is unknown instead of the password 😉

Leave a Reply

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