Workflow Tools Control Yard

Home / Logs

Event log query builder

Pick a log, event IDs, levels, a time span, an account or a data field. The page writes the XPath filter, the XML for a custom view or Filter Current Log in Event Viewer, a Get-WinEvent command and a wevtutil command, within the limits of the XPath that Windows Event Log supports.

Levels None ticked: all levels.
Audit result The keywords of the Security log.
Event data A named field of the event and the value it must have.

XPath, for -FilterXPath and wevtutil /q:

XML, for the XML tab of Create Custom View or Filter Current Log, and for -FilterXml

PowerShell, with a hash table

PowerShell, with the XML

Command prompt, with wevtutil

What a query looks at

Every event is XML: a System element, which every event has, then the event's own data, for example in EventData or UserData. An XPath query selects events by the elements and attributes of that XML:

PathWhat it holdsIn a query
System/EventIDThe event ID that the provider gave the event.EventID=4625
System/LevelThe severity: 1 Critical, 2 Error, 3 Warning, 4 Informational, 5 Verbose, 0 LogAlways.Level=2
System/KeywordsA bit mask of the event's keywords, compared with band(). Audit Success is 9007199254740992, Audit Failure 4503599627370496.band(Keywords,4503599627370496)
System/TimeCreated/@SystemTimeWhen the event was logged. timediff() gives its age in milliseconds.TimeCreated[timediff(@SystemTime) <= 86400000]
System/Provider/@NameThe provider that logged the event: the Source column of Event Viewer, usually.Provider[@Name='Microsoft-Windows-Security-Auditing']
System/Security/@UserIDThe SID of the user, as a string.Security[@UserID='S-1-5-18']
EventData/Data[@Name]A named data item of the event, such as TargetUserName in event 4625 of the Security log.EventData[Data[@Name='TargetUserName']='alice']

The XPath that Windows Event Log reads

Get-WinEvent and its hash table

-FilterHashtable takes keys such as LogName, ProviderName, Path, Keywords, ID, Level, StartTime, EndTime, UserID and Data, in any case, each once; LogName and ProviderName may hold wildcards. Keywords and Level have to be numbers, not names. Any other key is taken as the name of a field of the event data, with case counting: that works from PowerShell 6, not in Windows PowerShell 5.1, so for data fields there the page gives the XML form. Get-WinEvent returns the newest events first; -Oldest turns that around. Get-WinEvent -ListLog * lists the logs of the computer.

wevtutil qe reads a log (or a file, with /lf:true) with /q: and an XPath; /rd:true gives the newest events first, /c: limits the count and /f:text prints text instead of XML.

Sources

More Logs tools