반응형
XPath 사용 - Windows 이벤트 로그를 검색하기 위해 시작하거나 포함하는 기능
Windows 이벤트 뷰어에서 XML 필터 쿼리를 수동으로 편집하면 데이터가 문자열과 정확히 일치하는 이벤트를 찾을 수 있습니다.
<QueryList>
<Query Id="0" Path="Application">
<Select Path="Application">*[EventData[Data and (Data="Session end: imzcjflrrsq1sfdk3okc4jpf")]]</Select>
</Query>
</QueryList>
이제 부분 매치를 해보겠습니다.
<QueryList>
<Query Id="0" Path="Application">
<Select Path="Application">*[EventData[Data and (Data[starts-with(.,"Session")])]]</Select>
</Query>
</QueryList>
이벤트 로그에 다음 오류가 표시됩니다.
지정한 쿼리가 잘못되었습니다.
제가 구문을 잘못 알고 있나요?
Windows 이벤트 로그는 XPath 1.0의 하위 집합을 지원합니다.3가지 기능만 있습니다.position
,Band
,timediff
.
참조 : https://learn.microsoft.com/en-us/windows/desktop/WES/consuming-events#xpath-10-limitations
두 번만 통과해도 괜찮으시다면 파워셸 스크립트를 사용하여 데이터를 그대로 다시 필터링할 수 있습니다.-where
연산자 지원-like
,-match
,그리고.-contains
:
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'"
데이터에서 session*을(를) 검색할 수 있는 빠른 파워셸.데이터가 배열이라 하더라도 이는 작동해야 합니다.
get-winevent application | where { $xml = [xml]$_.toxml()
$xml.event.eventdata.data -like 'session*' } | select -first 3
ProviderName: Microsoft-Windows-Winlogon
TimeCreated Id LevelDisplayName Message
----------- -- ---------------- -------
2/22/2020 11:05:30 AM 6000 Information The winlogon notification subscriber <SessionEnv> was unavailable to handle a notification event.
2/22/2020 11:05:30 AM 6003 Information The winlogon notification subscriber <SessionEnv> was unavailable to handle a critical notification event.
2/21/2020 6:28:38 PM 6000 Information The winlogon notification subscriber <SessionEnv> was unavailable to handle a notification event.
$xml.event.eventdata.data # the last one
SessionEnv
정밀도가 필요하지 않은 경우에는 데이터 필드가 자주 나타나는 메시지와 일치하기가 더 쉽습니다.
get-winevent application | where message -match session
언급URL : https://stackoverflow.com/questions/8671194/using-xpath-starts-with-or-contains-functions-to-search-windows-event-logs
반응형
'programing' 카테고리의 다른 글
내 SQL 복제에 즉각적인 데이터 일관성이 있습니까? (0) | 2023.10.30 |
---|---|
C에 포인터를 사용하는 컨스트럭트 (0) | 2023.10.30 |
wp_insert_post를 사용하여 특징 이미지 설정 (0) | 2023.10.30 |
플래시가 설치되어 있는지 확인하고, 설치되어 있지 않은 경우 사용자에게 알려주는 숨겨진 디바를 표시하려면 어떻게 해야 합니까? (0) | 2023.10.30 |
워드프레스 필터에 추가 파라미터를 전달하는 방법은? (0) | 2023.10.30 |