I have the following code below I have to get down to under 260 characters. I had another post like this before and a powershell wizard came through and introduced me to wildcard matching, and although I spent hours studying what he did I can not figure out how to replicate the dark magic. Would someone be so kind to inform me. I have scoured the internet for reference and have failed on that front as well.
(netsh wlan show profiles) | sls "\:(.+)$" | %{$n=$_.Matches.Groups[1].Value.Trim(); $_} | %{(netsh wlan show profile name="$n" key=clear)} | sls "Key Content\W+\:(.+)$" | %{$p=$_.Matches.Groups[1].Value.Trim(); $_} | %{[PSCustomObject]@{ ssid=$n;pass=$p }}
This is the example the wizard showed me. My code above this needs to use the same technique to shorten it even further.
this:
Add-Type -AssemblyName System.Windows.Forms
to:
Add-Type -AssemblyName *m.W*s.F*s
System.Windows.Formsusing RegEx/Wildcard Patterns?switch -r(netsh wlan show profiles){'\:(.+)$'{$n = $Matches[1].Trim();switch -r(netsh wlan show profile name="$n" key=clear){'Key Content\W+\:(.+)$'{$p = $Matches[1].Trim();[PSCustomObject]@{ssid = $n; pass = $p}}}}}