【问题标题】:Powershell parsing system.array - netsh wlan show profilesPowershell 解析 system.array - netsh wlan 显示配置文件
【发布时间】:2022-01-22 02:35:54
【问题描述】:

我正在尝试自动获取 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 ...]

Output of netsh commands

【问题讨论】:

    标签: powershell automation scripting system.array


    【解决方案1】:

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

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

    参考https://regex101.com/r/mOtSHS/1

    【讨论】:

      猜你喜欢
      • 2015-09-16
      • 1970-01-01
      • 2015-11-22
      • 2014-08-10
      • 1970-01-01
      • 2015-06-08
      • 2021-02-23
      • 2015-11-21
      • 1970-01-01
      相关资源
      最近更新 更多