简体   繁体   中英

Powershell parsing system.array - netsh wlan show profiles

I'm trying to automate getting WiFi name & password. My biggest issue is parsing the output in system.array format. Since I can't simply access the value by its key. I'm loking for a way to make sure the parsing is not going to brake if run on a different PC.

> $all_profiles = netsh wlan show profile
> $all_profiles
Profiles on interface Wi-Fi:

Group policy profiles (read only)
---------------------------------
<None>

User profiles
-------------
All User Profile     : GRUBISIC
All User Profile     : HUAWEI
All User Profile     : A1
All User Profile     : Ma
All User Profile     : Ka
All User Profile     : Ou
All User Profile     : GK_Si
All User Profile     : 93
All User Profile     : 9B
All User Profile     : Li
All User Profile     : A
All User Profile     : NETI
All User Profile     : Re
All User Profile     : Chu

> $all_profiles.GetType()
IsPublic IsSerial Name                                     BaseType                                                                                                                                                                                                            
-------- -------- ----                                     --------                                                                                                                                                                                                            
True     True     Object[]                                 System.Array   

                                                                                                                                                                                                 

For now I'd like to parse it into the list of profle names, so: [GRUBISIC, HUAWEI...]

Output of netsh commands

Below works for me, there most likely is a fully PowerShell cmdlet to replace this but not sure which one:)

$all_profiles | Select-String 'All User Profile' | ForEach-Object {
    $_ -replace '(?<=\S)\s+:\s+(?=\S)','=' | ConvertFrom-StringData
}

See https://regex101.com/r/mOtSHS/1 for reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM