How to clear all Windows event logs

This guide shows a sample of a batch file to clear all Windows event logs.
It clears the following:

  • All logs under the Windows Logs:
    such as Application, System and so on.
  • All logs under the Applications and Services Logs

It’s useful when you create a Windows master image for deployment.

Sample of batch file

clear-evt.bat

wevtutil el > %cd%\EvtList.txt
for /f %%i in (EvtList.txt) do wevtutil cl "%%i"
wevtutil cl "System"
del %cd%\EvtList.txt

Comments

I’ll comment step by step.

wevtutil el > %cd%\EvtList.txt

To enumerate all name of logs, run wevtutil el and output the EvtList.txt.
“Name of logs” means such as Application, System, Security and so on.

for /f %%i in (EvtList.txt) do wevtutil cl "%%i"

Retrieve a name of log step by step from EvtList.txt.
To clear log, run sequential wevtutil cl <name of log> .

wevtutil cl "System"

After run wevtutil cl, like the following logs are written on System event log.

Those logs are written by the number of cleared log, so clear those at last.
Note: a log remains by running wevtutil cl “System” here.

del %cd%\EvtList.txt

At last, delete EvtList.txt.

That’s about it.