2013-03-14 57 views
0

我遇到問題只顯示命令的Time列。格式 - 表返回空白列

Get-EventLog -log Security | where {$_.EventID -eq 4800 -or $_.EventID -eq 4801} 

回報:

Index Time   EntryType Source     InstanceID Message                             
    ----- ----   --------- ------     ---------- -------                             
    167513 Mar 14 10:31 SuccessA... Microsoft-Windows...   4801 The workstation was unlocked....                       
    167506 Mar 14 10:14 SuccessA... Microsoft-Windows...   4800 The workstation was locked....                       
    167499 Mar 14 10:08 SuccessA... Microsoft-Windows...   4801 The workstation was unlocked.... 

但是,如果我只希望看到Time專欄中,我得到什麼:

獲取,事件日誌-log安全|其中{$ .EventID -eq 4800 - 或$ .EventID -eq 4801} |格式表時間

Time                                               
----                                               

任何想法?

回答

3

這是空白的,因爲沒有這樣的東西作爲Time屬性。這是在Get-EventLog的默認視圖中使用的別名。

PS > Get-EventLog -LogName System | gm 


    TypeName: System.Diagnostics.EventLogEntry#System/EventLog/2147489661 

Name      MemberType  Definition 
----      ----------  ---------- 
....          
TimeGenerated    Property  datetime TimeGenerated {get;} 
TimeWritten    Property  datetime TimeWritten {get;} 
UserName     Property  string UserName {get;} 
EventID     ScriptProperty System.Object EventID {get=$this.get_EventID() -band 0x... 

使用Format-Table TimeGenerated獲得了當年的事件happend,並TimeWritten得到它被保存到日誌的時間。

在默認視圖中列TimeTimeGenerated格式化等{0:MMM} {0:dd} {0:HH}:{0:mm}。你可以在Powershell的一個格式文件中看到它。對於這種情況,這是在 「C:\ WINDOWS \ SYSTEM32 \ WindowsPowerShell \ V1.0 \ DotNetTypes.format.ps1xml」:

..... 
<ViewSelectedBy> 
    <TypeName>System.Diagnostics.EventLogEntry</TypeName> 
</ViewSelectedBy> 
..... 
<TableColumnHeader> 
    <Label>Time</Label> 
    <Width>13</Width> 
</TableColumnHeader> 
..... 
<TableColumnItem> 
    <PropertyName>TimeGenerated</PropertyName> 
    <FormatString>{0:MMM} {0:dd} {0:HH}:{0:mm}</FormatString> 
</TableColumnItem> 
..... 
+0

驚人的 - 謝謝。 – 2013-03-14 12:21:22