wevtutil - Inspect event logs

Maintained on
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:

SubcommandShort formDescription
enum-logselList log names
query-eventsqeSearch and display events in a log
get-logglShow log settings (such as maximum size)
export-logeplExport a log to a file
clear-logclDelete 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 nameContents
ApplicationEvents recorded by applications
SystemEvents recorded by Windows itself, drivers, and services
SecuritySecurity 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
OptionMeaning
/c:<n>Maximum number of events to display
/rd:trueShow newest events first (the default is oldest first)
/f:textShow in human-readable text format (the default is XML)
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>wevtutil qe System /c:1 /rd:true /f:text
Event[0]:
Log Name: System
Source: Microsoft-Windows-Kernel-Power
Date: 2026-11-22T09:15:30.123
Event ID: 566
Level: Information
Computer: DESKTOP-ABC
Description:
…
C:\users\user>
Output varies by environment

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.

Without /rd:true, the oldest events come first

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:

ValueLevel
1Critical
2Error
3Warning
4Information

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:

RangeMilliseconds
1 hour3600000
24 hours86400000
7 days604800000

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
Event Viewer helps you build queries

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"
A cleared log cannot be restored

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.

When no events match

If no event matches the conditions, nothing is displayed, but this is not an error. The result file is simply empty.

Practice questions

Practice Problem

Which command displays the 5 latest events in the System log, newest first?

Choose one answer.

  1. wevtutil qe System /c:5
  2. wevtutil qe System /c:5 /rd:true
  3. wevtutil el System /c:5

Practice Problem

Which option saves a backup as an .evtx file before clearing a log?

Choose one answer.

  1. /rd:true
  2. /ow:true
  3. /bu:backup file
#Command Prompt #Batch file #Command line #Command #Event log #Administrator #Troubleshooting