|
Script to clear the Security event log after backing it up |
|
Wednesday, 02 July 2008 |
|
The following script clears the Security event log after backing it up to a folder mentioned in the script. To run the script, copy the following contents to Notepad, and save the file with .vbs extension. Double-click to run the file. strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate, (Backup, Security)}!\\" _ & strComputer & "\root\cimv2") Set colLogFiles = objWMIService.ExecQuery _ ("Select * from Win32_NTEventLogFile where LogFileName='Security'") For Each objLogfile in colLogFiles OutputFile = "C:\" & "Security " OutputFile = OutputFile & Day(Now) & "-" & month(now) & "-" & year(now) OutputFile = OutputFile & ".evt" errBackupLog = objLogFile.BackupEventLog(OutputFile) If errBackupLog = 0 Or errBackupLog = 183 Then objLogFile.ClearEventLog() Else Wscript.Echo "The Security event log could not be backed up." End If Next By default it backs up to C:\ root directory. You can change the path in the script accordingly. The backup file name format will be like this: (contains the date stamp) - Security 18-6-2008.evt
- Security 29-6-2008.evt
- Security 20-6-2008.evt
- Security 21-6-2008.evt
If the file with the same name already exists (which means the log has already been backed up for the current day), it ignores the error and clears the Security log.
|