diff --git a/Get-WirelessPassword.ps1 b/Get-WirelessPassword.ps1 new file mode 100644 index 0000000..2ee411d --- /dev/null +++ b/Get-WirelessPassword.ps1 @@ -0,0 +1,80 @@ +<# + +.SYNOPSIS +Gathers the SSID/Passwords for known wireless networks for a given computer or set of computers. + +.DESCRIPTION +Gathers the SSID/Passwords for known wireless networks for a given computer or set of computers. +Given a provided SSID, you can get the password for an individual SSID. + +.PARAMETER SSID +Defines the specific SSID to determine the password. If not provided, the script will gather all SSIDs. + +.PARAMETER ComputerName +Specifies the computers on which the command runs. The default is the local computer. + +.PARAMETER Credential +Credential that should be used to connect to a remote machine. + +.NOTES + Version: 1.0 + Author: Tyler Hale + Creation Date: 2022.05.26 + +#> + +[CmdletBinding()] +param ( + [Parameter(Mandatory = $false)] + [ValidateNotNull()] + $SSID, + [Parameter(Mandatory = $false)] + [ValidateScript( {Test-Connection $_ -Count 2})] + [alias('Cn')] + [string[]] + $ComputerName = $env:COMPUTERNAME, + [Parameter(Mandatory=$false, ValueFromPipeline=$true)] + [ValidateNotNull()] + [System.Management.Automation.PSCredential] + [System.Management.Automation.Credential()] + $Credential = [System.Management.Automation.PSCredential]::Empty +) + +############################################# [Internal Processing] ############################################## + +<# Build Remote Parameters #> +# Reference by appending @RemoteParameters to a command + +$RemoteParameters = @{} + +if ($ComputerName -ne $env:COMPUTERNAME) { + Write-Verbose "Adding $ComputerName to Remote Parameters splat variable" + $RemoteParameters['ComputerName'] = $ComputerName +} + +if ($Credential -ne [System.Management.Automation.PSCredential]::Empty) { + Write-Verbose "Adding provided credentials to Remote Parameters splat variable" + $RemoteParameters['Credential'] = $Credential +} + +################################################## [Execution] ################################################### + +if ($null -ne $SSID) { + Invoke-Command @RemoteParameters -ArgumentList $SSID -ScriptBlock { + $Password = (netsh wlan show profiles name=$($args[0]) key=clear | Select-String 'Key Content') -replace ".*:\s+" + if ("" -ne $Password) { + [PSCustomObject][ordered]@{"SSID"=$args[0];"Password"=$Password} + } + else { + Write-Host "Profile $($args[0]) is not found on the system." + } + } +} +else { + Invoke-Command @RemoteParameters -ScriptBlock { + foreach($SSID in ((netsh wlan show profiles | Select-String ': ' ) -replace ".*:\s+")) { + $Password = (netsh wlan show profiles name=$SSID key=clear | Select-String 'Key Content') -replace ".*:\s+" + [PSCustomObject][ordered]@{"SSID"=$SSID;"Password"=$Password} + } + } +} diff --git a/README.md b/README.md index 4df8ad9..005310b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,21 @@ -# get-wirelesspassword +# Get-WirelessPassword -Gathers the SSID/Passwords for known wireless networks for a given computer or set of computers. \ No newline at end of file +Gathers the SSID/Passwords for known wireless networks for a given computer or set of computers. + +## Variables + +| Variable | Required | Default | Choices | Description | +| ------------ | -------- | ------------- | ------- | ------------------------------------------------------------- | +| Path | No | All SSIDs | | Defines the specific SSID to determine the password. | +| ComputerName | No | Local Machine | | Specifies the computers on which the command runs | +| Credential | No | Running User | | Credential that should be used to connect to a remote machine | + +## Example + +```powershell +.\Get-WirelessPassword.ps1 +``` + +## License + +See LICENSE file for full license information.