0

I have the following text output in PowerShell derived from running netsh wlan show networks

SSID 1 : LSOX
    Network type            : Infrastructure
    Authentication          : WPA2-Personal
    Encryption              : CCMP 

SSID 2 : Embers_2ghz
    Network type            : Infrastructure
    Authentication          : WPA2-Personal
    Encryption              : CCMP 

SSID 3 : BRIGHTON_LEVEL1
    Network type            : Infrastructure
    Authentication          : WPA2-Personal
    Encryption              : CCMP 

SSID 4 : BRIGHTON_LEVEL2
    Network type            : Infrastructure
    Authentication          : WPA2-Personal
    Encryption              : CCMP 

SSID 5 : BRIGHTON_PRODUCTION
    Network type            : Infrastructure
    Authentication          : WPA2-Personal
    Encryption              : CCMP

This is what PowerShell I have now, but doesn't do what I want: (netsh wlan show networks) | Select-String -Pattern "(SSID .* : ?)" | % { $_.Matches[0].Value }

Using some sort of Select-String -Pattern expression I want to list only the names, so the output would be:

LSOX
Embers_2ghz
BRIGHTON_LEVEL1
BRIGHTON_LEVEL2
BRIGHTON_PRODUCTION

I am great at PowerShell, but crap at expressions, although I find them fascinating, here is one site I have been referencing http://powershell.com/cs/blogs/ebookv2/archive/2012/03/06/chapter-13-text-and-regular-expressions.aspx#regular-expressions

1 Answer 1

0

I think I worked it out.....

This seems to work:

(netsh wlan show networks) | Select-String -Pattern "(?<=SSID . : ).+" | % { $_.Matches[0].Value }
1
  • This assumes that the SSID is a single digit. You can cater for more via a pattern like "(?<=SSID \d+ : ).+".
    – dwarfsoft
    Feb 15, 2015 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.