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
CodePudding user response:
Technically what you're doing is code golf. It's ugly and not something that is usually recommended. If I recall correctly, for some reason you're trying to fit scripts like this into the Run box. This is the smallest I could get it with a decently described object at the end.
switch -r(netsh wl sh pr){':\s(. )'{$s=$matches.1;switch -r(netsh wl sh pr n=$s k=clear){'tent. :\s(. )'{[PSCustomObject]@{SSID=$s;Pass=$matches.1}}}}}