I'm trying to get unexpected shutdown times of Windows Sever 2008 machines via Get-EventLog
in Powershell. I can get close by searching for events with an EventID
of 6008 and selecting only message
, but I need to parse within the field to grab the time it occurred (not the time the event fired).
I've tried to use replacementstrings[x]
but I can't find how to specify the field to use (messages
) and can't get a result.
get-eventlog -LogName System -ComputerName svr-name | Where-Object {$_.EventID -eq 6008 -AND $_.timegenerated -gt (get-date).adddays(-30)}| select message
Produces this:
Message
-------
The previous system shutdown at 3:35:32 AM on 7/29/2014 was unexpected.
The previous system shutdown at 3:40:06 PM on 7/10/2014 was unexpected.`