Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Under Windows 7 you open the Event Viewer to browse several categories. You can also clear a single category by clicking Clear Log... on the right pane.

Assuming I want to clear ALL categories, am I supposed to click and clear them one by one?
There are dozens of them. Is there a faster way? Maybe with PowerShell?

enter image description here enter image description here

share|improve this question

3 Answers 3

up vote 6 down vote accepted

There's no way via the GUI to clear all logs at once. At least not that I've ever found. :)

Here's a batch file that uses WEVTUTIL to list the logs into a text file, and then use that text file to delete each of the logs.

WEVTUTIL EL > .\LOGLIST.TXT
for /f %%a in ( .\LOGLIST.TXT ) do WEVTUTIL CL "%%a"
del .\LOGLIST.TXT
timeout 30

As Logman pointed out in his answer, this can be further shortened down (and eliminate the need for the intermediate text file) by using something like (%'s double for batch file):

for /f %%a in ('WEVTUTIL EL') do WEVTUTIL CL "%%a"
timeout 30

Whichever way you choose, ensure you "Run As Administrator".

Easiest solution I've found. Been using it since Vista. :)

share|improve this answer
    
I was considering using WMI in a python script or similar - very good example of how batch can be an easier solution in certain scenarios. –  Lyle Brown Oct 6 '13 at 18:50
    
CMD output + Event viewer overview. Used your second example via batch as admin. Some categories can't be cleared? Strange. And Powershell categorie still has 11.511 events? All others seem to be cleared –  nixda Oct 6 '13 at 19:04
    
Screwed by a lack of quotes. sorry about that, fixed it. :) –  Ƭᴇcʜιᴇ007 Oct 6 '13 at 19:08
    
Is it possible to use this solution or the proposed by @Logman in Windows XP? I don't see it has wevtutil in the system. –  Sopalajo de Arrierez Apr 22 at 10:39
1  
@SopalajodeArrierez "wevtutil" is only available from Vista and above... technet.microsoft.com/en-us/library/cc732848.aspx –  Logman Apr 22 at 12:50

Open cmd prompt or create batch script and "run as admin":

for /f %x in ('wevtutil el') do wevtutil cl "%x"

Powershell code for clearing all event logs:

wevtutil el | Foreach-Object {Write-Host "Clearing $_"; wevtutil cl "$_"}

or pick and choose in a script:

wevtutil.exe cl Analytic
wevtutil.exe cl Application
wevtutil.exe cl DirectShowFilterGraph
wevtutil.exe cl DirectShowPluginControl
wevtutil.exe cl EndpointMapper
wevtutil.exe cl ForwardedEvents
wevtutil.exe cl HardwareEvents
wevtutil.exe cl Internet Explorer
wevtutil.exe cl Key Management Service
wevtutil.exe cl MF_MediaFoundationDeviceProxy
wevtutil.exe cl "Media Center"
wevtutil.exe cl MediaFoundationDeviceProxy
wevtutil.exe cl MediaFoundationPerformance
wevtutil.exe cl MediaFoundationPipeline
wevtutil.exe cl MediaFoundationPlatform
wevtutil.exe cl Microsoft-IE/Diagnostic
wevtutil.exe cl Microsoft-IEFRAME/Diagnostic
wevtutil.exe cl Microsoft-PerfTrack-IEFRAME/Diagnostic
wevtutil.exe cl Microsoft-PerfTrack-MSHTML/Diagnostic

etc...

You can get a complete list of all event category names by typing the following in a cmd prompt or powershell:

wevtutil el

More information can be found at MS TechNet. Examples:

Export events from System log to C:\backup\system0506.evtx:

wevtutil epl System C:\backup\system0506.evtx

Clear all of the events from the Application log after saving them to C:\admin\backups\a10306.evtx:

wevtutil cl Application /bu:C:\admin\backups\a10306.evtx
share|improve this answer
    
Nice shortened version. –  Ƭᴇcʜιᴇ007 Oct 6 '13 at 18:51

To delete obsolete log files produced by your servers/applications, I suggest you this useful open source tool: http://sourceforge.net/projects/autodeletions/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.