|
eventviewer
query
windows-event-log
xml
欄目
Windows
原文
原文鏈接
我正在嘗試在
Windows事件日志中搜索事件數(shù)據(jù)包含字符串TCP提供程序的任何內(nèi)容,錯誤:0作為較長錯誤消息的一部分.為此,我創(chuàng)建了以下代碼:
<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語句(因?yàn)樗雌饋硐襁@里使用的XPath語法的特殊版本.有誰知道我正在嘗試的是可能的/如何這樣做呢? 提前致謝, JB
你總是可以使用powershell腳本并通過powershell的where函數(shù)傳遞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'" 相關(guān)文章 |
|
|