我尝试使用Powershell截断wifi日志的第一行,但我不明白为什么它不起作用。谁能建议以下代码有什么问题?
(Get-WinEvent -Logname Microsoft-Windows-WLAN-AutoConfig/Operational | select -first 1).Message.split('`n')[0]
答案 0 :(得分:1)
尝试:
(Get-WinEvent -Logname Microsoft-Windows-WLAN-AutoConfig/Operational | select -first 1).Message.split("`n")[0]
单引号的字符串被视为文字,我想您是在字母'n'上分开的:)
答案 1 :(得分:1)
我认为您最好使用正则表达式-split
将消息拆分为换行符:
((Get-WinEvent -Logname Microsoft-Windows-WLAN-AutoConfig/Operational | Select-Object -First 1).Message -split '\r?\n')[0]
\r Match a carriage return character ? Between zero and one times, as many times as possible, giving back as needed (greedy) \n Match a line feed character