Option Explicit
Const ForReading=1,ForWriting=2
Dim strcomputer,objLogParser,objInputFormat,objOutputFormat,strQuery
Dim fso,tsInputFile,logOutputFile

Set fso = CreateObject("Scripting.FileSystemObject")
Set tsInputFile = fso.OpenTextFile("c:\scripts\logservers.txt", ForReading, False)'list of servers to get logs from
Set logOutputFile = fso.OpenTextFile("c:\scripts\LogConsolidationStatus.txt", ForWriting, True)'status output for running as a daily scheduled task

On Error Resume Next
logOutputFile.WriteLine "Start time: "& Time 
While Not tsInputFile.AtEndOfStream 'read the text file for input
	strcomputer=tsInputFile.ReadLine
	logOutputFile.WriteLine strcomputer & Time 'note the time each server starts so you know how long it takes to get logs from each server
	
	Set objLogParser = CreateObject("MSUtil.LogQuery") 'these will fail if you haven't registered the .dll
	Set objInputFormat = CreateObject("MSUtil.LogQuery.EventLogInputFormat")'set input type as Event Logs
	objInputFormat.iCheckpoint = "c:\scripts\"&strComputer&"icheckpoint.txt"'create a checkpoint file for each server in the text file
	
	Set objOutputFormat = CreateObject("MSUtil.LogQuery.CSVOutputFormat")'set output type as CSV
	objOutputFormat.headers=False'no header row
		
	strQuery="SELECT ComputerName, EventLog, EventTypeName, EventID, SourceName, Message, Strings, TimeGenerated INTO c:\logs\"&strComputer&"log.csv FROM \\"&strComputer&"\System,\\"&strComputer&"\Application"'choose the portions of each event to dump, create a file for each computer.  Overwrite daily.  Make sure the c:\logs folder exists or it will error.
	strQuery=strQuery & " WHERE (TimeGenerated > SUB( TO_LOCALTIME(SYSTEM_TIMESTAMP()), TIMESTAMP( '23:59:59', 'hh:mm:ss' ) ))"'only events in the last 24 hours
	
	objLogParser.ExecuteBatch strQuery, objInputFormat, objOutputFormat 'run the query
	
	If Err.Number <> 0 Then'write any errors to the status file
		logOutputFile.WriteLine strcomputer & Time & " - "&Err.Number & " - "&Err.Description & " - "&Err.Source
		Err.Clear
	End If
Wend
logOutputFile.WriteLine "End time: "& time
tsInputFile.Close
logOutputFile.Close