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 ...]
CodePudding user response:
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.