Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Event Logs for Errors that occured w/i last 7 Days 1

Status
Not open for further replies.
Apr 5, 2005
1,484
US
I would like to search the Event logs to echo only Type:Errors which have occured within the last 7 Days. This is for automating weekley server maintenance. I found a script that allows me to parse errors and one that only reads the last 7 days of log entries. The issue I am having is not understanding the logic of using both elements of each script into one.

Here is what I have attempeted:
strComputer = "."

Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")

DateToCheck = Date - 7
dtmEndDate.SetVarDate Date, True
dtmStartDate.SetVarDate DateToCheck, True


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

Set colLoggedEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'System'" _
& " and Type = 'Error'")

For Each objEvent in colLoggedEvents
Wscript.Echo "Event date: " & objEvent.TimeGenerated
Wscript.Echo "Description: " & objEvent.Message
Next

Thanks for any feedback...
 
also, I know I need to add the StartDate and EndDate in the objWMIService Query, just not sure of how to do this while maintaining the Query for Type: Error events.
 
you can add this to the query:

AND date BETWEEN #begin_date# and #end_date#

the variable name for date, you have to figure out what that is. as for the # sign, you might have to embed it withing the quote
" AND date BETWEEN #" & begin_date & "# and #" & end_date & "#
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top