Reputation: 8440
Sorry to ask such a question, but I've spent 1/2 hour on this and no good solution.
I want to get the latest date from the Event Log for a particular app. So far, my code is:
$event = get-eventlog -logname 'Windows PowerShell' -source mpkLogParser -newest 1 | Format-List
echo $event
this yields:
Index : 51
EntryType : Information
InstanceId : 3001
Message : MPKLogParser successfully parsed the log file u_ex100118.log
Category : (1)
CategoryNumber : 1
ReplacementStrings : {MPKLogParser successfully parsed the log file u_ex100118.log}
Source : mpkLogParser
TimeGenerated : 1/28/2010 11:24:08 AM
TimeWritten : 1/28/2010 11:24:08 AM
UserName :
So how do I extract the TimeWritten part from $event?
Any help with this and I can sleep better. :)
Upvotes: 1
Views: 3052
Reputation: 201612
Don't use Format-List unless you are displaying to the host. That is, don't use Format-List when assigning to a variable. Try this:
$name = 'Windows PowerShell'
$event = get-eventlog -logname $name -source mpkLogParser -newest 1
$event.TimeWritten
Upvotes: 7