I am trying to write a script (of which I have written ooooh…….all of one so far…ie this one) that backsup the Event log, clears it then moves it to another directory and renames it using the Date created FileSystemObject. I can get it to do the following
Backup the event log
Clear the event log
Move the Event log file to another directory
but I can’t get it to rename it using the date it was created
I have pasted the code I have written so far
Any suggestions would be greatly appreciated
On Error Resume Next
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate,(Backup)}!\\” & _
strComputer & “\root\cimv2”)
Set colLogFiles = objWMIService.ExecQuery _(“Select * from Win32_NTEventLogFile where LogFileName=’Application'”)
For Each objLogfile in colLogFiles
errBackupLog = objLogFile.BackupEventLog(“d:\application.evt”)
If errBackupLog <> 0 Then
Wscript.Echo “The Application event log could not be backed up.”
Else
objLogFile.ClearEventLog()
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFSO.GetFile(“d:\application.evt”)
Set objReadFile = objFSO.datecreated(“d:\application.evt”, 1) strContents = objFSO.datecreated
strPath = “objFSO.datecreated”
strFileName = objFSO.GetTempName
strFullName = objFSO.BuildPath(strPath, strFileName)
Set objFile = objFSO.CreateFile(strFullName)
objFile.Close
Set objFSO = CreatdObject(“Scripting.FileSystemObject”)
objFSO.MoveFile “d:\application.evt” , “e:\errorlogbackup\”
End If
Next
Many thanks in advance for help offered