Clearing all event logs


Here is the code to clean up all event logs in the current machine/server.

The code is in power shell, as some people feel this is the best language to write scripts on Windows.

strComputer = "." 
Set oWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Security)}!\\" & _
strComputer & "\root\cimv2" )
Set cLogFiles = oWMIService.ExecQuery _
("SELECT * FROM Win32_NTEventLogFile" )
For Each oLogfile in cLogFiles
Wscript.echo("Clearing Logfile " + oLogFile.Name)
oLogFile.ClearEventLog()
Next

Comments

Post a Comment

Popular posts from this blog

The pesky scrollbars on Remote desktop - Finally fixed!!

Exploring RedCritter - website for Agile project mangement

API Testing with Rest Assured - Validating the json schema