Created
April 16, 2026 17:43
-
-
Save stevenjudd/4195557fdc00c54fd109bf14f680a901 to your computer and use it in GitHub Desktop.
Get-sjWifiPassword
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-sjWifiPassword { | |
| <# | |
| .SYNOPSIS | |
| Gets the password of one or more wireless networks. | |
| .DESCRIPTION | |
| This function uses the netsh command to retrieve the password of one or more wireless networks | |
| that have been previously connected to the device. It returns an object with the network name and the password. | |
| .PARAMETER NetworkName | |
| Specifies the name of the wireless network to get the password for. If not specified, it will | |
| get the passwords for all wireless networks that have been previously connected to the device. | |
| This parameter accepts pipeline input by property name or by value. | |
| .EXAMPLE | |
| Get-sjWifiPassword | |
| This example gets the passwords for all wireless networks that have been previously connected | |
| to the device. | |
| .EXAMPLE | |
| Get-sjWifiPassword -NetworkName SETUP-D413 | |
| This example gets the password for the wireless network named SETUP-D413. | |
| .EXAMPLE | |
| 'setup-d413' | Get-sjWifiPassword | |
| This example gets the password for the wireless network named setup-d413 using pipeline input | |
| by value. | |
| .INPUTS | |
| System.String | |
| .OUTPUTS | |
| PSCustomObject | |
| .NOTES | |
| This function requires netsh command ($env:SystemRoot\System32\netsh.exe) to be in the proper | |
| location. It will throw an error if netsh command is not found or not accessible. | |
| #> | |
| param ( | |
| [parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)] | |
| [string[]]$NetworkName | |
| ) | |
| begin { | |
| if ((Get-Command -Name 'netsh').Source -ne "$env:SystemRoot\System32\netsh.exe") { | |
| throw 'netsh command is not in the proper location' | |
| } | |
| } | |
| process { | |
| if (-not ($PSBoundParameters.ContainsKey('NetworkName'))) { | |
| $NetworkName = ( | |
| netsh wlan show profile | Select-String ' : (.+)$' | |
| ).Matches.Groups.Where({ $_.Name -eq 1 }).Value | |
| } | |
| foreach ($item in $NetworkName) { | |
| [PSCustomObject]@{ | |
| Network = $item | |
| Password = ( | |
| netsh wlan show profile name="$item" key=clear | | |
| Select-String 'Key Content\s+:\s(.+)$' | |
| ).Matches.Groups.Where({ $_.Name -eq 1 }).Value | |
| } | |
| } | |
| } | |
| end {} | |
| } #end function Get-sjWifiPassword | |
| # test cases | |
| # Get-sjWifiPassword | |
| # Get-sjWifiPassword -NetworkName SETUP-D413 | |
| # Get-sjWifiPassword -NetworkName trash | |
| # Get-sjWifiPassword -NetworkName (1..4) | |
| # 'setup-d413' | Get-sjWifiPassword | |
| # 1..4 | Get-sjWifiPassword |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment