从get-eventlog获取值Powershell调用

问题描述:

对不起,提出这样一个问题,但我已经花了1/2小时在这个,没有好的解决方案。从get-eventlog获取值Powershell调用

我想从事件日志中获取特定应用程序的最新日期。到目前为止,我的代码是:

$event = get-eventlog -logname 'Windows PowerShell' -source mpkLogParser -newest 1 | Format-List 
echo $event 

这产生了:

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   : 

那么,如何提取TimeWritten部分从$事件?

任何帮助,我可以睡得更好。 :)

除非您显示给主机,否则不要使用Format-List。也就是说,分配给变量时不要使用Format-List。试试这个吧:

$name = 'Windows PowerShell' 
$event = get-eventlog -logname $name -source mpkLogParser -newest 1 
$event.TimeWritten 
+0

完美的是,在更多的阅读(和你的回应)之后,我喜欢这个返回的对象的实际列表,然后你可以操纵并得到你想要的东西。 谢谢基思。 – 2010-01-28 21:00:26