dim TrackingLogFile set TrackingLogFile = new clsLogReader TrackingLogFile.filename = strfilename TrackingLogFile.Delimiter = vbtab do while TrackingLogFile.GetNextRecord <> "EOF" wscript.echo TrackingLogFile.GetField("Date") Loop class clsLogReader '~ Generic Reader für any kind of CSV, IIS Logs. '~ Version 1.3 '~ Skip all lines with "#" as comments. '~ Try to use "#" Lines as header description. and remove anything in front of ":" character (Field: if IISLog etc.) '~ Samples: '~ # Exchange Message Tracking Log File '~ # Exchange System Attendant Version 6.5.7638.1 '~ # Date Time client-ip Client-hostname Partner-Name Server-hostname server-IP Recipient-Address Event-ID MSGID Priority Recipient-Report-Status total-bytes Number-Recipients Origination-Time Encryption service-Version Linked-MSGID Message-Subject Sender-Address '~ 2006-11-21 0:0:1 GMT 10.160.80.88 srv901.msxfaq.de - SRV01 10.160.1.19 User@zieldomain 1019 msgidUser@mail.absender.tld 0 0 2384 1 2006-11-21 0:0:1 GMT 0 Version: 6.0.3790.1830 - Betreff User@absender.tld - '~ 2006-11-21 0:0:1 GMT 10.160.80.88 srv901.msxfaq.de - SRV01 10.160.1.19 sUser@zieldomain 1025 msgidUser@mail.absender.tld 0 0 2384 1 2006-11-21 0:0:1 GMT 0 Version: 6.0.3790.1830 - Betreff User@absender.tld - '~ #Software: Microsoft Internet Information Services 6.0 '~ #Version: 1.0 '~ #Date: 2006-11-08 00:00:07 '~ #Fields: date time s-sitename s-ip cs-method cs-uri-stem cs-uri-query s-port cs-Username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status '~ 2006-11-08 00:00:07 W3SVC1 129.129.200.150 OPTIONS /Microsoft-Server-ActiveSync User=domain\User&DeviceId=IMEI3597380084&DeviceType=NokiaN73 80 - 172.25.1.200 NokiaN73/1.0 401 2 2148074254 private inputfilename, inputfs, inputfile, strline, strlogline private dictLine, strError, chrDelimiter, blnHeaderinFirstLine private Sub Class_Initialize set dictline = createobject("scripting.dictionary") strError = "" : chrDelimiter = " " : blnHeaderinFirstLine = false End Sub public property let Delimiter(wert) 'Configure delimiter to use chrDelimiter = wert end property public property let HeaderinFirstLine(wert) 'Configure delimiter to use blnHeaderinFirstLine = wert end property public property let filename(wert) ' Specify the filename to read if inputfilename <> "" then 'Close existing file inputfile.close : inputfile = nothing : inputfs = nothing end if inputfilename = wert ' open file if inputfilename <> "-" then objDebug.writeln "Logreader:Sourcefile: " & inputfilename, 5 Set inputfs = CreateObject("Scripting.FileSystemObject") Set inputfile = inputfs.OpenTextFile(inputfilename, 1, false) 'for readin else objDebug.writeln "Logreader:Sourcefile: STDIN", 3 set inputfile = wscript.stdin end if end property function GetNextRecord 'Fill object with next valid line or return "EOF" dim blnReady, arrtemp, count,field blnReady = false do while (not inputfile.AtEndOfStream) and (not blnready) strlogline = inputfile.readline if strlogline = "" then objDebug.writeln "Logreader:Emtry Line", 5 elseif (instr(strlogline ,"#") = 1) or (blnHeaderinFirstLine and (inputfile.line = 2)) then ' line is 2 after the first line was read objDebug.writeln "Logreader:GetNextRecord:Neuer Header/Comment", 3 if instr(strlogline ,":") <> 0 then strlogline = mid(strlogline ,instr(strlogline ,":")+1) 'Start at ":" else strlogline = mid(strlogline ,2) 'Start at ":" end if dictline.removeall arrtemp = split(trim(strlogline),chrDelimiter) for count = 0 to ubound(arrtemp) ' Skip "#fields:" objDebug.writeln "Logreader:GetNextRecord:Add Header definition:" & trim(cstr(arrtemp(count))), 6 dictline.add trim(cstr(arrtemp(count))),empty next objDebug.writeln "Logreader:GetNexRecord: TotalField:" & ubound(arrtemp)+1, 5 else objDebug.writeln "Logreader:GetNexRecord: Proc Line:" & strlogline, 6 arrtemp = split(strlogline ,chrDelimiter) if dictline.count <= ubound(arrtemp)+1 then if dictline.count = ubound(arrtemp)+1 then objDebug.writeln "Logreader:GetNexRecord: Header/Field count exactmatch" & strlogline, 6 else objDebug.writeln "Logreader:GetNexRecord: Header/Field count partmatch: To many data entries" & strlogline, 6 end if count = 0 for each field in dictline.keys dictline.item(field) = trim(arrtemp(count)) count = count +1 next blnReady = true else objDebug.writeln "Logreader:GetNexRecord: Header/Field count mismatch: Data missing" & strlogline, 2 end if end if loop if blnready then objDebug.writeln "Logreader: OK", 6 GetNextRecord = "OK" strError = "OK" elseif inputfile.AtEndOfStream then objDebug.writeln "Logreader: EOF", 5 GetNextRecord = "EOF" strError = "EOF" else objDebug.writeln "Logreader: WARNING: Exit and not BLNReady or EOF", 2 GetNextRecord = "WRN" strError = "WRN" end if end function function GetField(strFieldname) ' Returns a given field. if dictline.exists (strFieldname) then GetField = dictline.item(strFieldname) objDebug.writeln "Logreader: GetField OK :" & strFieldName, 6 strError = "OK" else GetField = "" objDebug.writeln "Logreader: Requested field not existing:" & strFieldname, 2 strError = "NA" end if end function function FieldExists(wert) ' Returns true, if field is declared FieldExists = dictline.exists (wert) end function function GetRawLine ' returns current line GetRawLine = strlogline strError = "OK" end function function GetLastError ' Get last processing error GetLastError = strError end function end class