tags:

views:

64

answers:

1

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. :)

+4  A: 

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
Keith Hill
Perfect, after more reading (and your response), I like that this returns the actual list of objects that you can then manipulate and get exactly what you want out of it.Thanks Keith.
Mark Kadlec