I'm working on an event log script, that will read from a text file a list of computers, and export the event log for the "System" log of that computer. It was working well before I added reading from a list of computers...can anyone help? Also...I am looking to maybe add for the future, an option to select only certain event ID's, more than 1.
Code:
'name of this script: logarchive.vbs
'- [URL unfurl="true"]http://www.ftponline.com/wss/2004_12/magazine/features/kgardinier/page2.aspx[/URL]
'- [URL unfurl="true"]http://www.go-itservices.com/Windows_Server_2003_Maintenance_Strategy.pdf[/URL]
'- [URL unfurl="true"]http://safari.samspublishing.com/0672326671/index?indexview=L[/URL] (search: Logs)
'----------------------------------------------------------------------
Dim sFile, sFolder
sFile = "C:\Event Logs\serverlist.txt"
sFolder = "C:\Event Logs"
Dim oFSO, oTS
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FolderExists(sFolder) Then
WScript.Echo "Destination folder does not exist"
WScript.Quit
End If
If Not oFSO.FileExists(sFile) Then
WScript.Echo "Input file does not exist"
WScript.Quit
End If
Dim sClient, oWMIService, cLogFiles, oLogfile
Dim errBackupLog, sOutfile
Set oTS = oFSO.OpenTextFile(sFile)
Do Until oTS.AtEndOfStream
sClient = oTS.ReadLine
'-------------------------------------------------------------------
strArchiveFolder = "C:\EventLogs"
Set WS = CreateObject("Wscript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
DateString = CurrentDate()
Purge = False 'True = clears currrent logs
'on error resume next
StartTime = Now
Output "---------------------------------"
OutPut "Started at: " & CStr(Now)
Output ""
Set oWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Backup)}!\\" & _
sClient & "\root\cimv2")
If Err.Number = 0 Then
Set colLogs = oWMIService.ExecQuery("select * from Win32_NTEventLogFile",,48)
For Each refLog In colLogs
LogName = sClient& "_" & LogFileName(refLog.LogFileName) & _
"_" & DateString
If FSO.FileExists(strArchiveFolder & "\" & LogName & ".evt") Then _
FSO.DeleteFile(strArchiveFolder & "\" & LogName & ".evt")
If Purge Then
RetVal = reflog.ClearEventlog(strArchiveFolder & "\" & LogName & ".evt")
Else
RetVal = reflog.BackupEventlog(strArchiveFolder & "\" & LogName & ".evt")
End If
If RetVal = 0 Then
Output vbTab & "Log was archived in .evt format: " & LogName & ".evt"
If Purge Then Output vbTab & "All events were cleared from the log"
Else
Output vbTab & "Error while archiving in .evt format."
End If
Next
Else
Output vbTab & "Failed connect to the server"
End If
Set colLogs = Nothing
Set refLogs = Nothing
Set oWMIService = Nothing
Output "----------------------------------------"
OutPut "Finished at: " & CStr(Now)
Output ""
Output ""
Loop
oTS.Close
Set WS = Nothing
Set FullLog = Nothing
Set FSO = Nothing
msgbox "Script Complete!"
WScript.Quit(0)
Function CurrentDate
Today = Date
If Month(Today) < 10 Then
CurrentDate = "0" & CStr(Month(Today))
Else
CurrentDate = CStr(Month(Today))
End If
If Day(Today) < 10 Then
CurrentDate = CurrentDate & "0" & CStr(Day(Today))
Else
CurrentDate = CurrentDate & CStr(Day(Today))
End If
CurrentDate = CurrentDate & CStr(Year(Today))
If Hour(Time) < 10 Then
CurrentDate = CurrentDate & "0" & CStr(Hour(Time))
Else
CurrentDate = CurrentDate & CStr(Hour(Time))
End If
End Function
Function LogFileName(LogName)
Select Case LogName
'Case "Application"
'LogFileName = "app"
'Case "Directory Service"
'LogFileName = "dir"
'Case "DNS Server"
'LogFileName = "dns"
'Case "File Replication Service"
'LogFileName = "rep"
'Case "Security"
'LogFileName = "sec"
Case "System"
LogFileName = "sys"
End Select
End Function
Sub Output(Text)
End Sub