整形输出netsh的内容

时间:2024-01-11 15:56:20
$raw = netsh wlan show network mode=bssid
$ssids = $raw | Select-String -Pattern 'SSID\b'| Select-String -Pattern '\bBSSID\s[^1]\b' -NotMatch | ForEach-Object {
$_.ToString().PadRight() + '_' #有些扫描出来的SSID没有名字, 这会造成后续的格式错误. 所以我干脆让所有SSID名称后都加一个下划线.
}
$ssids2 = $ssids -split '\b\s\d{1,}\s{1,}[:]\s+\b'| select-string -Pattern 'SSID\b' -NotMatch #分割字符, SSID | <SSIDNAME> | BSSID | <MAC Address>
for($i=;$i -lt $ssids2.Count;$i=$i+){
#$ssids2[$i].ToString().Substring(,$ssids2[$i].ToString().Length-)
#$ssids2[$i+].ToString().Substring(,$ssids2[$i+].ToString().Length-)
[pscustomobject]@{
    ssidname=$ssids2[$i].ToString().Substring(,$ssids2[$i].ToString().Length-);
    macaddress=$ssids2[$i+].ToString().Substring(,$ssids2[$i+].ToString().Length-)} |
      Export-Csv -Path ('f:\' + (Get-Date).Hour.ToString() + (Get-Date).Minute.ToString() + (Get-Date).Minute.ToString() + '.csv') -Encoding Default -Append -NoTypeInformation
}

PS C:\WINDOWS\system32> $ssids

SSID 1 : vo_
BSSID 1 : 08:e8:4f:fc:05:80_
SSID 2 : VIPGuest_
BSSID 1 : bc:67:1c:58:08:72_
SSID 3 : ve鐨刬Mac_
BSSID 1 : b8:09:8a:d8:71:53_
SSID 4 : APEC_
BSSID 1 : d2:7e:35:b6:64:62_

PS C:\WINDOWS\system32> $ssids2

vo_
08:e8:4f:fc:05:80_
VIPGuest_
bc:67:1c:58:08:72_
ve鐨刬Mac_
b8:09:8a:d8:71:53_
APEC_
d2:7e:35:b6:64:62_