How do I Clear All Windows Event Viewer Logs using cmd, PowerShell, c# or VBScript WMI?

Windows Event Viewer displays all the detailed information such as Errors, Warnings and even normal activities. Event Log at times doesn’t automatically remove all the information it stores, and that can be a problem for your computer’s performance as well. This article will show you how to quickly clear all Windows event logs in Event Viewer as needed in Windows 10 using command prompt, PowerShell script, c# command or VBScript / WMI.

Windows Event Viewer logs
Windows Event Viewer logs

Content Summary

Clear all Windows Event Viewer Logs using Command Prompt
Clear all Windows Event Viewer Logs using PowerShell
Clear all Windows Event Viewer Logs using C#
Clear all Windows Event Viewer Logs using BAT or CMD file
Clear all Windows Event Viewer Logs using VBScript / WMI

Clear all Windows Event Viewer Logs using Command Prompt

Step 1: Open Command Prompt and run it as administrator.

Step 2: Type or copy paste the following command into the elevated command prompt and press Enter:
for /F "tokens=*" %1 in ('wevtutil.exe el') DO wevtutil.exe cl "%1"

Clear all Windows Event logs using command prompt
Clear all Windows Event logs using command prompt

Clear all Windows Event Viewer Logs using PowerShell

Step 1: Open an elevated PowerShell prompt.

Step 2: Type or copy paste below command into PowerShell window and press Enter.
wevtutil el | Foreach-Object {wevtutil cl "$_"}
or
Get-EventLog -LogName * | ForEach { Clear-EventLog $_.Log }

Clear all Windows Event logs using PowerShell
Clear all Windows Event logs using PowerShell

Step 3: Type Exit to close PowerShell window

* This process does not clear Analytic or Debug logs. If you have them enabled, wevutl returns an error, but the other logs are cleared.

Clear all Windows Event Viewer Logs using C#

foreach (var eventLog in EventLog.GetEventLogs())
{
eventLog.Clear();
eventLog.Dispose();
}

Clear all Windows Event Viewer Logs using BAT or CMD file

Step 1: Copy and paste below command into the notepad and save it as .bat or .cmd file:
@echo off
FOR /F "tokens=1,2*" %%V IN ('bcdedit') DO SET adminTest=%%V
IF (%adminTest%)==(Access) goto noAdmin
for /F "tokens=*" %%G in ('wevtutil.exe el') DO (call :do_clear "%%G")
echo.
echo All Event Logs have been cleared!
goto theEnd
echo clearing %1
wevtutil.exe cl %1
goto :eof
echo Current user permissions to execute this .BAT file are inadequate.
echo This .BAT file must be run with administrative privileges.
echo Exit now, right click on this .BAT file, and select "Run as administrator".
pause >nul
Exit

Step 2: Execute the file with Run as administrator.

Clear all Windows Event Viewer Logs using VBScript / WMI

Step 1: Copy and paste below command into the notepad and save it as ClearEvent.vbs (VBScript)
strComputer = ”.”
Set objWMIService = GetObject(“winmgmts:” _
& ”{impersonationLevel=impersonate, (Backup, Security)}!\” _
& strComputer & ”rootcimv2”)
Set colLogFiles = objWMIService.ExecQuery _
(“Select * from Win32_NTEventLogFile”)
For each objLogfile in colLogFiles
objLogFile.ClearEventLog()
Next

Step 2: Move ClearEvent.vbs to C:/Windows/System32

Step 3: Open Command Prompt as administrator and run the following command:
CScript ClearEvent.vbs