我在 Windows 終端中運行命令:
PS E:\> netsh wlan show profile name="wifi_profile" key=clear | findstr "Key Content"
Key Content : password1234
所以在這里我試圖在任何組態檔的輸出password123中只獲取(wifi密碼)
powershell中有什么方法可以做到嗎?
uj5u.com熱心網友回復:
在像這樣的簡單情況下,您可以使用-replace運算子修剪線條中不需要的部分:
(
netsh wlan show profile name="wifi_profile" key=clear | findstr "Key Content"
) -replace '^. ?: '
正則運算式 ^. ?: 匹配從開始 ( ^) 一個或多個 ( ) 字符 ( .) 非貪婪 ( ?) 直到 (first):后跟一個空格,并且 - 在沒有傳遞給替換運算元的情況下-replace- 用空字串替換它,即有效地洗掉它,從而只回傳值部分。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/414565.html
標籤:
