Event log check



Hi ,

I am running a script to find the event log errors for a group of servers.

--------------------
Const ForReading = 1
Const ForAppending = 8
Const CONVERT_TO_LOCAL_TIME = True


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
DateToCheck = CDate("4/3/2007")
dtmStartDate.SetVarDate DateToCheck, CONVERT_TO_LOCAL_TIME
dtmEndDate.SetVarDate DateToCheck -7, CONVERT_TO_LOCAL_TIME

Set objTextFile = objFSO.OpenTextFile _
("C:\servers.txt", ForReading)

Set objTextFile1 = objFSO.OpenTextFile _
("C:\service_status.txt", ForAppending, True)


Set objTextFile2 = objFSO.OpenTextFile _
("C:\log_status.txt", ForAppending, True)

Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrServiceList = Split(strNextLine , ",")


strComputer = arrServiceList(0)

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")



Set colRunningServices = objWMIService.ExecQuery("Select * from
Win32_Service")

For Each objService in colRunningServices
if objService.StartMode = "Auto" then
if objService.State= "Stopped" then
objTextFile1.WriteLine arrServiceList(0) &vbtab & objService.DisplayName &
VbTab & objService.State
End if
End if
Next
Set colEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where TimeWritten >= '" & dtmStartDate
& "' and TimeWritten < '" & dtmEndDate & "'")


For Each objEvent in colEvents

if objEvent.Type = "error" then
objTextfile2.WriteLine "Computer Name: " & arrServiceList(0) _
& vbtab & objEvent.SourceName _
& vbtab & objEvent.TimeWritten _
& vbtab & objEvent.Type _
& vbtab & objEvent.User
End if
Next


Loop
----------------------------
The problem is this script checks the logs only for the day 4/3/2007.

I want to find the log error for period of time. For example: The time now
to last 7 days. ie. 4/3/2007 to 4/10/2007..

Please help me in this.

Regards,
George.

.



Relevant Pages

  • Request: Help With PC Inventory Script
    ... I am trying to write a script to get basic pc information and write it to a tab delimted text file. ... "Computer Model"& vbtab & _ ... "/root/default:StdRegProv") objReg.EnumKey HKLM, strKey, arrSubkeys ... If strValue1 "" Then ...
    (microsoft.public.scripting.vbscript)
  • Re: Win32_Product query hangs when logged into Domain
    ... Are your running this script locally on the DC or accessing it remotely? ... Is it doing other things in addition to being a domain controller? ... Set colSoftware = objWMIService.ExecQuery _ ... objTextFile.WriteLine objSoftware.Caption & vbtab & _ ...
    (microsoft.public.windows.server.scripting)
  • Re: open latest file
    ... would like the script to automatically open the newest one. ... ArrayList sort routine. ... Array(oFile.DateLastModified, vbTab, oFile.Path)) ... I'll have to try out your sprintf routine. ...
    (microsoft.public.scripting.vbscript)
  • Re: VBTab question
    ... 14:09, step schrieb: ... > the script writes lines to a text file like this... ... > vbtab obviously tidies thing up into neat colums but i need to keep each ... console windows use fixed-length fonts ...
    (microsoft.public.scripting.vbscript)
  • Re: Event log check
    ... dtmStartDate.SetVarDate DateToCheck, CONVERT_TO_LOCAL_TIME ... I am running a script to find the event log errors for a group of servers. ... Set objTextFile = objFSO.OpenTextFile _ ... VbTab & objService.State ...
    (microsoft.public.windows.server.scripting)

Loading