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.
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:
| Path | What it holds | In a query |
|---|---|---|
System/EventID | The event ID that the provider gave the event. | EventID=4625 |
System/Level | The severity: 1 Critical, 2 Error, 3 Warning, 4 Informational, 5 Verbose, 0 LogAlways. | Level=2 |
System/Keywords | A bit mask of the event's keywords, compared with band(). Audit Success is 9007199254740992, Audit Failure 4503599627370496. | band(Keywords,4503599627370496) |
System/TimeCreated/@SystemTime | When the event was logged. timediff() gives its age in milliseconds. | TimeCreated[timediff(@SystemTime) <= 86400000] |
System/Provider/@Name | The provider that logged the event: the Source column of Event Viewer, usually. | Provider[@Name='Microsoft-Windows-Security-Auditing'] |
System/Security/@UserID | The 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
- Only a subset of XPath 1.0. A query must select events, so it starts with
*orEvent, and only the child and attribute (@) axes work. - The operators are
and,or,=,!=,<,<=,>,>=and parentheses, and the functions Microsoft lists areposition()(on leaf nodes only),band()andtimediff(). In XPath 1.0, two strings are equal only when they are the same sequence of characters, so a*in a value is just a*: a provider or a user name has to be written in full. band(a, b)is true when the bitwise AND of two numbers is not zero; it tests keywords.timediff(@SystemTime)is the number of milliseconds from the event to now (to a second time, if one is given).timediff(@SystemTime) <= 86400000is the last 24 hours, counted when the query runs.- A plain XPath of more than 20 expressions, or a query of more than one log, needs the XML form. Each
SelectorSuppressin it can hold up to 32 expressions. The page counts each comparison and function as one expression and says when it is over. - In the XML form,
Suppressleaves out what aSelectof the same log would include; when both match an event, Suppress wins. Each Suppress needs a Select with the same Path.
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
- The XPath subset, its functions and limits, the structured query and the event schema: Microsoft's Windows Event Log pages Consuming Events, QueryType Complex Type, EventType Complex Type and the System and EventData element pages (win32 at commit bc82a65).
- The example fields TargetUserName and LogonType: Microsoft's page on event 4625, An account failed to log on (Windows 10 previous versions, last updated 29 Mar 2026), read with a page fetch on 24 Nov 2026.
- How = compares two strings and how a literal is quoted: the W3C's XML Path Language (XPath) Version 1.0, sections 3.4 and 3.7, read with a page fetch on 24 Nov 2026.
- Get-WinEvent, its hash table keys, levels and keywords: Microsoft's Get-WinEvent reference for PowerShell 5.1 and 7.6 and its article Creating Get-WinEvent queries with FilterHashtable (PowerShell-Docs at commit aedd8ef). wevtutil: Microsoft's wevtutil reference (windowsserverdocs at commit b640f2c). Microsoft's documentation is used under the Creative Commons Attribution 4.0 International licence (creativecommons.org/
licenses/ by/ 4.0/).
More Logs tools
-
Access log checker
Find the exploit requests in a web server log and the addresses that sent them.
-
Windows security event ID lookup
Look up 4740, 4625, 4728, 1102 or any other Security log event: its meaning, audit setting and criticality.
-
auditpol command builder
Choose what each audit subcategory logs, or start from Microsoft's baseline: the auditpol commands, with GUIDs.
-
Sysmon event ID lookup
Every Sysmon event ID with its filter tag and fields, and a reader for an event pasted from Event Viewer.
-
Windows Firewall log reader
Open pfirewall.log: its lines as a table, the drops by port and address, and the commands that turn logging on.
-
Schannel and TLS alert code lookup
Read Schannel events 36887 and 36888 and TLS alerts such as 40, 46, 48 and 70.
-
IIS status codes and log line reader
Look up 500.19, 403.14 or any other IIS status and substatus, or read W3C log lines field by field.
-
Syslog PRI calculator
Read the facility and severity in a syslog priority such as <134>, or build one from local0 to local7.
-
Timestamp converter
Unix seconds and milliseconds, FILETIME, Chrome, Apple, Excel and MS-DOS dates to a date, and back.
-
Scanner watch
What attack tools ask of this site's web server: the addresses, the paths and the networks, rebuilt each day.