I highly recommend using LogParser for this task:
logparser -i:evt file:query.sql
With query.sql containing something like this:
SELECT TimeGenerated,EventID,SourceName,Message FROM Application WHERE TimeGenerated > TO_TIMESTAMP(SUB(TO_INT(SYSTEM_TIMESTAMP()), 1209600)) ORDER BY TimeGenerated DESC
A somewhat unintuitive date calculation converts the system time ( SYSTEM_TIMESTAMP() ) to an integer ( TO_INT() ), subtracts 1209600 seconds (60 * 60 * 24 * 14 = 2 weeks) and converts the result back to a time TO_TIMESTAMP() ), which gave a date from 2 weeks ago.
You can parameterize the time interval by replacing a fixed number of seconds with MUL(86400, $days) and changing the command line to this:
logparser -i:evt file:query.sql+days=14
You can also pass the request directly to logparser:
logparser -i:evt "SELECT TimeGenerate,EventID,SourceName,Message FROM ..."
Ansgar wiechers
source share