vbscript for backup all event logs and delete them afterwards

Option Explicit
dim strComputer
dim objWMIService
dim colLogFiles
dim objLogfile
dim errBackupLog

strComputer = "." 'IP Address or Name
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Backup)}!\\" & strComputer & "\root\cimv2")

Call eventlogbackup("Application")
Call eventlogbackup("System")
Call eventlogbackup("Security")
'Call eventlogbackup("DNS Server") Define further logs here

Function eventlogbackup(logtype)
Set colLogFiles = objWMIService.ExecQuery ("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='" &logtype &"'")
For Each objLogfile in colLogFiles
errBackupLog = objLogFile.BackupEventLog("\\server\eventlogs\" &strComputer &"\" &logtype &".evt")
If errBackupLog <> 0 Then
Wscript.Echo "The " &logtype &" event log could not be backed up."
Wscript.Echo "The " &logtype &" event log is backed up."
End If
End Function

No comments: