2015-11-27 70 views
0

我正在使用PowerShell來搜索應用程序的特定錯誤。我的代碼正在工作,但在輸出中是重複的eventID,消息等。我只需要一種消息。可能嗎?在PowerShell中獲取事件日誌

$date=(Get-Date).AddDays(-5) 
$file = New-item -type file "C:\event.txt" -force 
Get-EventLog -LogName 01-D -EntryType Error -After $date | 
Where {$_.EventId -eq 1 -or $_.EventId -in 3..13371 -or $_.EventId -in 13373..21003 -or $_.EventId -in 21005..21007 -or $_.EventId -in 21009..49498 -or $_.EventId -in 49500..53519 -or $_.EventId -in 53521..62200 -or $_.EventId -in 62202..64494 -or $_.EventId -in 64496..99999 -and $_.EventId -ne 21050} | 
Sort-Object eventid | format-list -Property EventId,MachineName,EntryType, Message | out-file $file -Encoding default 
+1

使用的'-unique'參數[選擇 - 的出現次數對象(https://technet.microsoft.com/en-us/library/hh849895.aspx) –

回答

0

則可以使用選擇對象與-unique參數或一組對象與-noelements參數,讓你可以計算每個事件