Posts

Showing posts from February 5, 2012

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