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.

7 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 😉

  3. Pingback: Get SSL Labs Test Result PowerShell - It for DummiesIt for Dummies

  4. Hello, your script didn’t manage very well SSIDs with a space in it (returned an “Unknown” Key) where the command line returned one. I refactored it this way, and now it works 🙂

    Thanks a lot for the advice, I never used PS to handle returns from legacy command line tools, and now I think I’ve the right toolkit to do so 🙂

    Function Get-WifiPassword {
    $WifiProfiles = $(netsh wlan show profile | Select-Object -Skip 3 | Where-Object -FilterScript {($_ -like ‘:‘)} | % { $.Split(‘:’)[-1].trim() })
    $ReturnArray = @()
    ForEach ($WifiProfile in $WifiProfiles) {
    $Profile = ” | Select -Property Name,Key
    $Key = $(netsh wlan show profile name = $WifiProfile key=clear) | Where-Object -FilterScript {($
    -like ‘contenu‘) -or ($_ -like ‘key content‘)} | % { $_.Split(‘:’)[-1].trim() }
    $Profile.Name = $WifiProfile
    if ($Key -ne $null) {
    $Profile.Key = $Key
    } else {
    $Profile.Key = “Unknown”
    }
    $ReturnArray += $Profile
    }
    $ReturnArray
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

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