81 lines
2.7 KiB
PowerShell
81 lines
2.7 KiB
PowerShell
|
<#
|
||
|
|
||
|
.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}
|
||
|
}
|
||
|
}
|
||
|
}
|