事件日志>filter当前日志> XML>其中EventData包含文本

我试图通过Windows事件日志search任何事件数据包含stringTCP提供程序,错误:0作为一个较长的错误消息的一部分。 为此,我创build了下面的代码:

<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> 

然而,这被视为一个无效的查询 – 我猜包含语句不被识别(因为它看起来像一个特殊版本的XPath语法正在使用这里。有谁知道我是否尝试可能/如何去做这个?

提前致谢,

JB

你总是可以使用powershell脚本并通过powershell的where函数(支持-contains-like -match)来传递XML:

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'" 

在进一步的调查中,我遇到了堆栈溢出的答案: https : //stackoverflow.com/questions/8671194/using-xpath-starts-with-or-contains-functions-to-search-windows-event-logs

所以看起来不可能在事件日志中进行通配符search。