2014-03-28 93 views
1

我想查找多個服務器的某個事件ID列表的最近一次出現次數。我沒有看到一個很好的方法來做到這一點。如果我使用-newest交換機,我必須根據每臺服務器的事件日誌的相對大小以及我有興趣在該條目數量內發生的事件的機率來使用該數字。在我下面的示例中,服務器F6WINMSSTEST3沒有我在前10000條中找到的內容。任何人都知道這樣做的好方法?Powershell Get-eventlog查詢。如何返回符合標準的條目數量爲

我想列出每個服務器每個服務器的每個ID的最新條目的單個實例,以便我可以看到它們何時發生。在一個完美的世界裏,每個服務器都會列出最近的3個ID。

$Servers = "F6WINMSSTEST","F6WINMSSTEST2","F6WINMSSTEST3","F6WINMSSTEST4","F6WINMSSTEST5" 

Foreach ($server in $Servers) { 

$server 

get-eventlog -computer $server -logname system -newest 10000 | where-object { $_.eventid - eq 6005 -or $_.eventid -eq 6009 -or $_.eventid -eq 6006} } 

輸出示例:

F6WINMSSTEST 

    Index Time   EntryType Source     InstanceID Message                                
    ----- ----   --------- ------     ---------- -------                                
    108265 Feb 08 08:33 Information EventLog    2147489653 The Event log service was started.                          
    108264 Feb 08 08:33 Information EventLog    2147489657 Microsoft (R) Windows (R) 6.01. 7601 Service Pack 1 Multiprocessor Free.                
    108247 Feb 08 08:31 Information EventLog    2147489654 The Event log service was stopped.                          
    104703 Nov 16 08:41 Information EventLog    2147489653 The Event log service was started.                          
    104702 Nov 16 08:41 Information EventLog    2147489657 Microsoft (R) Windows (R) 6.01. 7601 Service Pack 1 Multiprocessor Free.                
    104688 Nov 16 08:39 Information EventLog    2147489654 The Event log service was stopped.                          
F6WINMSSTEST2 
    39265 Jul 06 08:01 Information EventLog    2147489653 The Event log service was started.                          
    39264 Jul 06 08:01 Information EventLog    2147489657 Microsoft (R) Windows (R) 6.00. 6002 Service Pack 2 Multiprocessor Free.                
    39249 Jul 06 08:00 Information EventLog    2147489654 The Event log service was stopped.                          
    39060 Jul 06 02:03 Information EventLog    2147489653 The Event log service was started.                          
    39059 Jul 06 02:03 Information EventLog    2147489657 Microsoft (R) Windows (R) 6.00. 6002 Service Pack 2 Multiprocessor Free.                
    39044 Jul 06 02:02 Information EventLog    2147489654 The Event log service was stopped.                          
F6WINMSSTEST3 
F6WINMSSTEST4 
    6591 Jul 06 08:01 Information EventLog    2147489653 The Event log service was started.                          
    6590 Jul 06 08:01 Information EventLog    2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Uniprocessor Free.                 
    6589 Jul 06 08:00 Information EventLog    2147489654 The Event log service was stopped.                          
    6531 Jul 05 11:52 Information EventLog    2147489653 The Event log service was started.                          
    6530 Jul 05 11:52 Information EventLog    2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Uniprocessor Free.                 
    6529 Jul 05 11:51 Information EventLog    2147489654 The Event log service was stopped.                          
F6WINMSSTEST5 
    55124 Nov 06 19:11 Information EventLog    2147489653 The Event log service was started.                          
    55123 Nov 06 19:11 Information EventLog    2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Uniprocessor Free.                 
    55122 Nov 06 19:10 Information EventLog    2147489654 The Event log service was stopped. 

回答

0

我寫的,然後刪除了這個帖子了幾次,現在我想我找到了這是怎麼回事。

  • 任何有將事件寫入日誌條目寫到一個叫場「事件ID」
  • 這並沒有真正包含事件ID,它實際上包含了值的高位一些額外的數據
  • 的事件查看器/ PowerShell /等等去掉高位,並將結果顯示爲EventId
  • 它們將原始值表示爲InstanceId,它們可能與EventID匹配,但可能不匹配。

這導致以下情況:

  • 兩個完全不同的事件可能具有相同的事件ID,它可能會發生衝突。你還必須檢查'源'是你想要的。
  • 通過PowerShell獲取EventID的速度很慢,獲取InstanceId的速度很快,因爲它已編入索引。

因此,對於你的問題,如果你能得到每個這些事件中的一個,然後獲取實例id,那麼你可以要求Get-EventLog您所關心的事件InstanceIds然後用-newest 1

嘗試:

$Servers = "F6WINMSSTEST","F6WINMSSTEST2","F6WINMSSTEST3","F6WINMSSTEST4","F6WINMSSTEST5" 

ForEach ($server in $Servers) { 
    Write-Output $server 
    Get-EventLog -computer $server -LogName System -InstanceId ?,?,? -Newest 1 
} 

當你發現instanceIDs。

指定-Source也許是個好主意。

否則這個討論:http://social.technet.microsoft.com/Forums/scriptcenter/en-US/616b67ee-9e71-4f23-abb8-5c88e8890b9e/event-logs-relationship-between-instanceid-and-eventid?forum=ITCG是我得到了上述情況,並有人爲你同樣的問題,他們發表評論:

的Get-WinEvent cmdlet接受-FilterXML參數,在其中可以 指定EventID。所以這就解決了上位機 的問題,但是對於下位機(我希望有更好的方法 說「2000-XP-2K3」/「Vista-7-2008」),我們仍然需要事實後,過濾器 ,如果你明白我的意思。

如果你能去的實例ID應該是快很多,但我希望看到一個權威性的參考是說,這是穩定可靠的,或者不能發生衝突,或者類似的。

0

在我的查詢中,回報一直列在最新到最舊。這使得這個命令的工作只能帶回最新的:

get-eventlog -logname system | where ((eventid -eq 6005) -or (eventid -eq 6006) -or (eventid -eq 6009)) | select -first 1 
相關問題