我正在嘗試自動獲取 WiFi 名稱和密碼。我最大的問題是決議 system.array 格式的輸出。因為我不能簡單地通過它的鍵訪問該值。我正在尋找一種方法來確保決議在不同的 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
現在我想把它決議成組態檔名稱串列,所以:[GRUBISIC, HUAWEI ...]
netsh 命令的輸出
uj5u.com熱心網友回復:
下面對我有用,很可能有一個完整的 PowerShell cmdlet 來替換它,但不確定是哪個 :)
$all_profiles | Select-String 'All User Profile' | ForEach-Object {
$_ -replace '(?<=\S)\s :\s (?=\S)','=' | ConvertFrom-StringData
}
請參閱https://regex101.com/r/mOtSHS/1以供參考。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/389642.html
