ProductivityTools.PSGetCurrentWifiPassword.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function Get-CurrentWifiPassword {

    [cmdletbinding()]
    param()

    $wifiNetwork=Get-NetConnectionProfile |where InterfaceAlias -eq 'Wi-Fi'
    if ($wifiNetwork -eq $null)
    {
        throw "Wi-Fi network not detected, are you connected?"
    }
    $wifiName=$wifiNetwork.Name
    Write-Verbose "Current Wi-Fi name: $wifiName"
    
    $currentWifi=Get-WifiPassword -NetworkName $wifiName
    $password=$currentWifi.Password
    
    
    return $password

}

Export-ModuleMember Get-CurrentWifiPassword