Link to home
Start Free TrialLog in
Avatar of thomasd04
thomasd04Flag for United States of America

asked on

I need to query WMI for data less than 7 days old

I'm simply trying to pull data from the event log for errors and critical errors for the past 7 days. I'm having a problem doing the query using the WMI date format (UTC). I'd prefer to have this done within the query if possible. Can anyone help?

Looking for something like this:
"SELECT * from Win32_NTLogEvent WHERE Logfile = 'System' AND TYPE = 'ERROR' AND TIMEGENERATED > [TODAYS DATE - 7 DAYS]"



Avatar of merowinger
merowinger
Flag of Germany image

Avatar of thomasd04

ASKER

Sorry, not quite sure how this would work. I need to the UTC date of 7 days ago in the query. Datediff gives me the difference between two dates; but I already have that number (7 days). I need to come up with the 'start' date. Or am I not understanding your suggestion?
SOLUTION
Avatar of merowinger
merowinger
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks! I'll check on this Monday when I go back to work.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great suggestions. However, I'm using kix to pull the data and I don't have a DateAdd function to use. But this did give me an idea. I just need to pull current date in WMI format, subtract the 7 days, and then use it in the query. I just need to figure out how to get today's date in WMI.
Although I'm not using VBS the suggestions pointed me in the direction I needed to go to get the job done.