【问题标题】:Netsh output in csv with Powershell带有Powershell的csv中的Netsh输出
【发布时间】:2017-02-23 05:07:32
【问题描述】:

如何格式化 Windows 命令的输出,

c:\netsh wlan show networks mode=bssid

如下 csv,

myWifinameA,Infrastructure,WPA2-Personal,CCMP,bc:9c:31:36:05:60,80%,802.11n,10,1 2 5.5 11,6 9 12 18 24 36 48 54
myWifinameB,Infrastructure,WPA2-Personal,CCMP,d4:61:2e:c6:b2:6e,75%,802.11n,5,1 2,5.5 6 9 11 12 18 24 36 48 54

也尝试过使用 Python,但我无法摆脱空格。

【问题讨论】:

标签: python powershell csv


【解决方案1】:

Building off this functionGet-WifiNetwork

Get-WifiNetwork | select SSID, 'Network Type', Authentication, Encryption, 'BSSID 1'

似乎收集了您需要的所有信息。

以防链接在未来的功能代码中变坏

function Get-WifiNetwork {
 end {
  netsh wlan sh net mode=bssid | % -process {
    if ($_ -match '^SSID (\d+) : (.*)$') {
        $current = @{}
        $networks += $current
        $current.Index = $matches[1].trim()
        $current.SSID = $matches[2].trim()
    } else {
        if ($_ -match '^\s+(.*)\s+:\s+(.*)\s*$') {
            $current[$matches[1].trim()] = $matches[2].trim()
        }
    }
  } -begin { $networks = @() } -end { $networks|% { new-object psobject -property $_ } }
 }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-23
    • 1970-01-01
    • 2015-07-25
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    相关资源
    最近更新 更多