wevtutil - Inspect event logs
Table of Contents
The wevtutil command lets you view, export, and clear Windows event logs from the command prompt.
When a PC restarts suddenly or an app crashes, the event log often holds clues about the cause. You would normally check it in Event Viewer, but with wevtutil you can pull out only the events you need, save the result to a file, or investigate automatically from a batch file.
Basic syntax of the wevtutil command
wevtutil <subcommand> [arguments] [options]
The subcommand you specify first decides what the command does. The commonly used ones are:
| Subcommand | Short form | Description |
|---|---|---|
enum-logs | el | List log names |
query-events | qe | Search and display events in a log |
get-log | gl | Show log settings (such as maximum size) |
export-log | epl | Export a log to a file |
clear-log | cl | Delete the events in a log |
This article covers the main ones. See wevtutil /? for the rest.
List logs (el)
Use el to see which logs exist.
wevtutil el
This prints a list of several hundred lines. The three representative logs are:
| Log name | Contents |
|---|---|
Application | Events recorded by applications |
System | Events recorded by Windows itself, drivers, and services |
Security | Security events such as sign-in success or failure (auditing) |
To look for a specific log, pipe the output to find.
wevtutil el | find "PowerShell"
Display events (qe)
Specify a log name after qe to display that log’s events.
wevtutil qe System /c:3 /rd:true /f:text
| Option | Meaning |
|---|---|
/c:<n> | Maximum number of events to display |
/rd:true | Show newest events first (the default is oldest first) |
/f:text | Show in human-readable text format (the default is XML) |
The output above is only an example. The event contents and field labels vary with the state of the PC and the OS display language.
If you specify only /c:, the given number of events is shown from the beginning of the log (the oldest events). When investigating something recent, always combine it with /rd:true.
Filter by condition (/q)
If you give the /q: option an XPath query, only the events that match are returned.
Filter by level
Show the 5 newest errors (level 2).
wevtutil qe System /q:"*[System[(Level=2)]]" /c:5 /rd:true /f:text
The Level values are:
| Value | Level |
|---|---|
1 | Critical |
2 | Error |
3 | Warning |
4 | Information |
To get both critical events and errors, join them with or.
wevtutil qe System /q:"*[System[(Level=1 or Level=2)]]" /c:10 /rd:true /f:text
Filter by event ID
Specify the event ID. For example, ID 41 (Kernel-Power) is recorded when the PC restarted without shutting down cleanly.
wevtutil qe System /q:"*[System[(EventID=41)]]" /c:3 /rd:true /f:text
Filter by time range
timediff(@SystemTime) returns the time elapsed since the event was recorded, in milliseconds. This example checks errors and warnings from the last 24 hours (86,400,000 ms).
wevtutil qe System /q:"*[System[(Level=2 or Level=3) and TimeCreated[timediff(@SystemTime) <= 86400000]]]" /rd:true /f:text
You can combine conditions with and. Commonly used ranges:
| Range | Milliseconds |
|---|---|
| 1 hour | 3600000 |
| 24 hours | 86400000 |
| 7 days | 604800000 |
Filter by provider
You can also filter by the name of the provider that recorded the event. Because the whole query is enclosed in ", use ' inside it.
wevtutil qe System /q:"*[System[Provider[@Name='Microsoft-Windows-Kernel-Power']]]" /c:3 /rd:true /f:text
In Event Viewer, set conditions with “Create Custom View” and open the “XML” tab to see the XPath query for the same conditions. You can reuse it in /q:.
Back up a log (epl)
epl exports a log to an .evtx file. You can open the exported file in Event Viewer.
wevtutil epl System "%USERPROFILE%\Desktop\System-backup.evtx"
If a file with the same name already exists, an error occurs. Add /ow:true to overwrite it.
wevtutil epl System "%USERPROFILE%\Desktop\System-backup.evtx" /ow:true
To read a saved .evtx file, add /lf:true to qe so that the path of the file is used in place of a log name.
wevtutil qe "%USERPROFILE%\Desktop\System-backup.evtx" /lf:true /c:3 /rd:true /f:text
Clear a log (cl)
cl deletes all events in a log.
wevtutil cl Application
With /bu:<file>, a backup is saved as an .evtx file before the log is cleared.
wevtutil cl Application /bu:"%USERPROFILE%\Desktop\Application-backup.evtx"
If you clear a log without a backup, records you may need to investigate a problem are lost. The Security log in particular may be required to be kept as an audit trail. Before running this, make a backup with epl or /bu:.
When administrator rights are required
Displaying System and Application works with normal permissions, but displaying the Security log and clearing logs require a Command Prompt run as administrator. Without enough permissions, an error such as Access is denied. appears.
For how to start it as an administrator, see
.Using it in a batch file
This example saves the errors from the last 24 hours to a file.
@echo off
set "OUT=%~dp0recent-errors.txt"
wevtutil qe System /q:"*[System[(Level=1 or Level=2) and TimeCreated[timediff(@SystemTime) <= 86400000]]]" /rd:true /f:text > "%OUT%"
if errorlevel 1 (
echo Failed to get the event log.
exit /b 1
)
echo Saved the result to: %OUT%
The > (redirect) writes the output to a file. %~dp0 represents the folder that contains the batch file itself.
If no event matches the conditions, nothing is displayed, but this is not an error. The result file is simply empty.