-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGet-WifiPassword.psm1
56 lines (48 loc) · 1.93 KB
/
Get-WifiPassword.psm1
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
<#
.SYNOPSIS
Function to get wifi password
.DESCRIPTION
Prints password to the console
.PARAMETER WifiName
Determine the name of the Wi-Fi
.EXAMPLE
PS> Get-WifiPassword
.EXAMPLE
PS> Get-WifiPassword -name WIFINAME
.NOTES
Filename: Get-WifiPassword.psm1
Author: Jacquin Moon
Email: [email protected]
Date: January 6th, 2025
#>
function Get-WifiPassword {
[alias('wifipass')]
param ([Alias('n', 'name')][string]$WifiName)
if (!$WifiName) {
$wifiList = netsh wlan show profiles | Select-String -Pattern "All User Profile\s+:\s+(.*)" | ForEach-Object { $_.Matches.Groups[1].Value }
if (Get-Command gum -ErrorAction SilentlyContinue) {
$WifiName = gum choose --header="Choose an available Wi-Fi name:" $wifiList
}
elseif (Get-Command fzf -ErrorAction SilentlyContinue) {
$WifiName = $wifiList | fzf --prompt="Select Wi-Fi > " --height=~80% --layout=reverse --border --exit-0 --cycle --margin="2,40" --padding=1
}
else {
for ($i = 0; $i -lt $wifiList.Count; $i++) {
Write-Host "[$i] $($wifiList[$i])"
}
$index = $(Write-Host "Enter the corresponding number of Wi-Fi name: " -ForegroundColor Magenta -NoNewline; Read-Host)
if ($null -ne $index) {
if ($index -match '^\d+$' -and [int]$index -lt $wifiList.Count) {
$WifiName = $wifiList[$index]
} else { return }
}
}
}
$WifiPassword = netsh wlan show profile name="$WifiName" key=clear | Select-String -Pattern "Key Content\s+:\s+(.+)" | ForEach-Object { $_.Matches.Groups[1].Value }
if (!$WifiPassword) { Write-Warning "No password available for Wi-Fi $WifiName"; return }
else {
Write-Verbose "Prints password for Wi-Fi $WifiName"
Write-Output $WifiPassword
}
}
Export-ModuleMember -Function Get-WifiPassword -Alias wifipass