Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thisisthetechie/a04267460c334f8e95ccd73627d87c69 to your computer and use it in GitHub Desktop.
Save thisisthetechie/a04267460c334f8e95ccd73627d87c69 to your computer and use it in GitHub Desktop.
Prints Wifi passwords from a remote machine by using Powershell remoting
#Make a list with all WiFi SSID's and passwords stored locally on Windows OS.
Param (
[string] $ComputerName
)
Invoke-Command -ComputerName $ComputerName -ScriptBlock {
$output = netsh.exe wlan show profiles
$profileRows = $output | Select-String -Pattern 'All User Profile'
$profileNames = New-Object System.Collections.ArrayList
#for each profile name get the SSID and password
for($i = 0; $i -lt $profileRows.Count; $i++){
$profileName = ($profileRows[$i] -split ":")[-1].Trim()
$profileOutput = netsh.exe wlan show profiles name="$profileName" key=clear
$SSIDSearchResult = $profileOutput| Select-String -Pattern 'SSID Name'
$profileSSID = ($SSIDSearchResult -split ":")[-1].Trim() -replace '"'
$passwordSearchResult = $profileOutput| Select-String -Pattern 'Key Content'
if($passwordSearchResult){
$profilePw = ($passwordSearchResult -split ":")[-1].Trim()
} else {
$profilePw = ''
}
$networkObject = New-Object -TypeName psobject -Property @{
ProfileName = $profileName
SSID = $profileSSID
Password = $profilePw
}
$profileNames.Add($networkObject) | Out-Null
}
$profileNames | Sort-Object ProfileName | Select-Object ProfileName, SSID, Password | Format-Table
}
#blog help source: https://blogs.technet.microsoft.com/heyscriptingguy/2015/11/23/get-wireless-network-ssid-and-password-with-powershell/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment