PS using Get-WinEvent with FilterXPath and datetime variables?

Posted by Jordan W. on Stack Overflow See other posts from Stack Overflow or by Jordan W.
Published on 2012-01-23T22:31:40Z Indexed on 2012/06/08 4:40 UTC
Read the original article Hit count: 401

  • I'm grabbing a handful of events from an event log in chronological order
  • don't want to pipe to Where
  • want to use get-winevent

After I get the Event1, I need to get the 1st instance of another event that occurs some unknown amount of time after Event1. then grab Event3 that occurs sometime after Event2 etc.

Basically starting with:

$filterXML = @'
<QueryList>
  <Query Id="0" Path="System">
    <Select Path="System">*[System[Provider[@Name='Microsoft-Windows-Kernel-General'] and (Level=4 or Level=0) and (EventID=12)]]</Select>
  </Query>
</QueryList>
'@    
$event1=(Get-WinEvent -ComputerName $PCname -MaxEvents 1 -FilterXml $filterXML).timecreated

Give me the datetime of Event1. Then I want to do something like:

Get-WinEvent -LogName "System" -MaxEvents 1 -FilterXPath "*[EventData[Data = 'Windows Management Instrumentation' and TimeCreated -gt $event1]]"

Obviously the timecreated part bolded there doesn't work but I hope you get what I'm trying to do. any help?

© Stack Overflow or respective owner

Related posts about datetime

Related posts about powershell