I have been asked to find out when a user has logged on to the system in the last week. Now the audit logs in Windows should contain all the info I need. I think if I search for Event ID 4624 (Logon Success) with a specific AD user and Logon Type 2 (Interactive Logon) that it should give me the information I need, but for the life of my I cannot figure out how to actually filter the Event Log to get this information. Is it possible inside of the Event Viewer or do you need to use an external tool to parse it to this level?
I found http://nerdsknowbest.blogspot.com.au/2013/03/filter-security-event-logs-by-user-in.html which seemed to be part of what I needed. I modified it slightly to only give me the last 7 days worth. Below is the XML I tried.
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[(EventID=4624) and TimeCreated[timediff(@SystemTime) <= 604800000]]]</Select>
<Select Path="Security">*[EventData[Data[@Name='Logon Type']='2']]</Select>
<Select Path="Security">*[EventData[Data[@Name='subjectUsername']='Domain\Username']]</Select>
</Query>
</QueryList>
It only gave me the last 7 days, but the rest of it did not work.
Can anyone assist me with this?
EDIT
Thanks to the suggestions of Lucky Luke I have been making progress. The below is my current query, although as I will explain it isn't returning any results.
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">
*[System[(EventID='4624')]
and
System[TimeCreated[timediff(@SystemTime) <= 604800000]]
and
EventData[Data[@Name='TargetUserName']='john.doe']
and
EventData[Data[@Name='LogonType']='2']
]
</Select>
</Query>
</QueryList>
As I mentioned, it wasn't returning any results so I have been messing with it a bit. I can get it to produce the results correctly until I add in the LogonType line. After that, it returns no results. Any idea why this might be?
EDIT 2
I updated the LogonType line to the following:
EventData[Data[@Name='LogonType'] and (Data='2' or Data='7')]
This should capture Workstation Logons as well as Workstation Unlocks, but I still get nothing. I then modify it to search for other Logon Types like 3, or 8 which it finds plenty of. This leads me to believe that the query works correctly, but for some reason there are no entries in the Event Logs with Logon Type equalling 2 and this makes no sense to me. Is it possible to turn this off?