Windows-Event-Log
事件日誌 > 過濾目前日誌 > XML > 其中 EventData 包含文本
我正在嘗試在 Windows 事件日誌中搜尋事件數據包含字元串TCP Provider, error: 0作為較長錯誤消息的一部分的任何內容。為此,我創建了以下程式碼:
<QueryList> <Query Id="0" Path="Application"> <Select Path="Application">*[System[Provider[@Name='MyDemo' or @Name='AnotherDemo'] and (Level=2 or Level=3)]][EventData[Data[contains(.,'TCP Provider, error: 0')]]]</Select> </Query> </QueryList>
但是,這被視為無效查詢-我猜 contains 語句未被辨識(因為它看起來像這裡使用了 XPath 語法的特殊版本。有誰知道我正在嘗試的是否可行/如何去做這個?
提前致謝,
JB
您始終可以使用 powershell 腳本並通過 powershell 的 where 函式傳遞 XML(支持 -contains -like -match):
nv.ps1
$Query = @" <QueryList> <Query Id="0" Path="System"> <Select Path="System"> *[System[(EventID=20001)]] </Select> </Query> </QueryList> "@ $events = Get-WinEvent -FilterXml $Query ForEach ($Event in $Events) { # Convert the event to XML $eventXML = [xml]$Event.ToXml() Add-Member -InputObject $Event -MemberType NoteProperty -Force -Name DriverVersion -Value $eventXML.Event.UserData.InstallDeviceID.DriverVersion Add-Member -InputObject $Event -MemberType NoteProperty -Force -Name DriverDescription -Value $eventXML.Event.UserData.InstallDeviceID.DriverDescription Add-Member -InputObject $Event -MemberType NoteProperty -Force -Name Data -Value $eventXML.Event.EventData.Data } $Events | Select TimeCreated, Id, DriverDescription, DriverVersion, ProviderName, @{Name="MessageData";Expression={$_.Message + $_.Data}} | Where {$_.DriverDescription -match "NVIDIA GeForce GTX*"} | Out-GridView pause
啟動它的 cmd (nv.cmd):
powershell.exe -executionpolicy bypass "& '.\nv.ps1'"