0

我正在尝试自动获取 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 命令的输出

4

1 回答 1

0

下面对我有用,很可能有一个完整的 PowerShell cmdlet 来替换它,但不确定是哪个 :)

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

请参阅https://regex101.com/r/mOtSHS/1以供参考。

于 2021-12-20T13:37:23.477 回答