Advertisement
Neantro

PS netsh.exe

Jun 15th, 2016
1,636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Make a list with all WiFi SSID's and passwords stored locally on Windows OS.
  2.  
  3. $output = netsh.exe wlan show profiles
  4. $profileRows = $output | Select-String -Pattern 'All User Profile'
  5. $profileNames = New-Object System.Collections.ArrayList
  6.  
  7. #for each profile name get the SSID and password
  8. for($i = 0; $i -lt $profileRows.Count; $i++){
  9.     $profileName = ($profileRows[$i] -split ":")[-1].Trim()
  10.    
  11.     $profileOutput = netsh.exe wlan show profiles name="$profileName" key=clear
  12.    
  13.     $SSIDSearchResult = $profileOutput| Select-String -Pattern 'SSID Name'
  14.     $profileSSID = ($SSIDSearchResult -split ":")[-1].Trim() -replace '"'
  15.  
  16.     $passwordSearchResult = $profileOutput| Select-String -Pattern 'Key Content'
  17.     if($passwordSearchResult){
  18.         $profilePw = ($passwordSearchResult -split ":")[-1].Trim()
  19.     } else {
  20.         $profilePw = ''
  21.     }
  22.    
  23.     $networkObject = New-Object -TypeName psobject -Property @{
  24.         ProfileName = $profileName
  25.         SSID = $profileSSID
  26.         Password = $profilePw
  27.     }
  28.     $profileNames.Add($networkObject)
  29. }
  30.  
  31. $profileNames | Sort-Object ProfileName | Select-Object ProfileName, SSID, Password
  32.  
  33. #blog help source: https://blogs.technet.microsoft.com/heyscriptingguy/2015/11/23/get-wireless-network-ssid-and-password-with-powershell/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement