从get eventlog Powershell调用获取值

从get eventlog Powershell调用获取值,powershell,Powershell,很抱歉问这样一个问题,但我已经花了半个小时在这个问题上,没有好的解决办法 我想从特定应用程序的事件日志中获取最新日期。到目前为止,我的代码是: $event = get-eventlog -logname 'Windows PowerShell' -source mpkLogParser -newest 1 | Format-List echo $event 这将产生: Index : 51 EntryType : Information Insta

很抱歉问这样一个问题,但我已经花了半个小时在这个问题上,没有好的解决办法

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

$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           : 
那么如何从$event中提取timewrited部分呢


如果能帮上忙,我就能睡得更好

除非向主机显示,否则不要使用格式列表。也就是说,在分配给变量时不要使用格式列表。试试这个:

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

除非向主机显示,否则不要使用格式列表。也就是说,在分配给变量时不要使用格式列表。试试这个:

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

很好,经过更多的阅读和你的回答,我喜欢它返回实际的对象列表,然后你可以操纵它,并从中得到你想要的东西。谢谢Keith。太好了,在阅读和回答之后,我喜欢这个返回实际的对象列表,然后你可以操纵它,从中得到你想要的东西。谢谢你,基思。