Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Convert One Liner to more readable Code

$
0
0

Hi together,

 

i have the following One Liner to show the saved SSID's and passwords for WiFi Networks known to Windos:

(netsh wlan show profiles) | Select-String "\:(.+)$" | %{$name=$_.Matches.Groups[1].Value.Trim(); $_} | %{(netsh wlan show profile name="$name" key=clear)}  | Select-String "Key Content\W+\:(.+)$" | %{$pass=$_.Matches.Groups[1].Value.Trim(); $_} | %{[PSCustomObject]@{ PROFILE_NAME=$name;PASSWORD=$pass }} | Format-Table -AutoSize

I've tried to make the Code more readable and the following is what i got so far but it didn't work:

$networks = netsh wlan show profiles | Select-String "\:(.+)$"

 

foreach ($network in $networks) {

    $name = $network.Matches.Groups[1].Value.Trim()

    netsh wlan show profile name="$name" key=clear | Select-String "Key Content\W+\:(.+)$"

    $pass = $network.Matches.Groups[1].Value.Trim()

    [PSCustomObject]@{ PROFILE_NAME=$name;PASSWORD=$pass}

    Format-Table -AutoSize

}

I#m pretty sure the error begins at the line with PSCustomObject in the foreach loop but i didn't get it.

Is anyone able to help me understand where my error is?

Thanks!


Viewing all articles
Browse latest Browse all 6937

Trending Articles