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.
Table of Contents
Clear all Windows Event Viewer Logs using Command Prompt
- Open Command Prompt and run it as administrator.
- 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 Viewer Logs using PowerShell
- Open an elevated PowerShell prompt.
- 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 }
- 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
- 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
- Execute the file with Run as administrator.
Clear all Windows Event Viewer Logs using VBScript / WMI
- 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
- Move ClearEvent.vbs to
C:/Windows/System32
- Open Command Prompt as administrator and run the following command:
CScript ClearEvent.vbs