-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-WlanPasswords.ps1
61 lines (35 loc) · 1.23 KB
/
Get-WlanPasswords.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<#PSScriptInfo
.VERSION 1.1
.GUID cb19eb4b-062a-410b-aafc-9e1d455892c6
.AUTHOR CBlais
.COMPANYNAME Vertikal6
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA
.DESCRIPTION "Gets the saved SSIDs and passwords"
#>
##Get and cleanProfiles
$Netsh = netsh.exe wlan show profiles
$profileRows = $Netsh | Select-String -Pattern 'All User Profile'
#For each profile name get the SSID and password
$RawProfiles = Foreach ($Row in $profileRows) {$Row -split ":" | ? {$_ -notlike "*All User Profile*"}}
$RawPasswords = Foreach ($Profile in $RawProfiles.trim()) {
##Catch errors resulting from 802.1x SSIDs
if (netsh.exe wlan show profiles name="$Profile" key=clear | Select-String -SimpleMatch "802.1X") {Write-Output "802.1X"}
Else {(netsh.exe wlan show profiles name="$Profile" key=clear | Select-String -Pattern 'Key Content').ToString().Split(":")[1].Trim()}}
##Create hash table of SSID/Password values
$Count = 0
$HashTable = @{}
While ($Count -lt $RawProfiles.Count) {
$HashTable.Add($RawProfiles.GetEnumerator().trim()[$Count],$RawPasswords[$Count])
$Count +=1
}
##Output
$HashTable.GetEnumerator() | Sort-Object -Property Name