#later : $machines=@("127.0.0.1","another_host")
$machines=@("127.0.0.1")
$Format=@{Expression={($_.Date).ToShortDateString()};Label="Date";width=21},`
@{Expression={($_.EventID).ToString()};Label="EventID";width=7},`
@{Expression={$_.Source};Label="Index";width=25},`
@{Expression={$_.Message};Label="Message"}, `
@{Expression={$_.Count};Label="Count";width=7}
ForEach ($machine in $machines) {
echo "***************************************************************"
echo $machine
$logs=[System.Diagnostics.EventLog]::GetEventLogs($machine)
Foreach ($log in $logs) {
$Entrees = $log.Entries | Where-Object {$_.EntryType -eq "Error"}
# Sort the List by Date then Event ID
$Entrees = $Entrees | Select-Object @{n='Date';e={ (Get-Date($_.TimeGenerated)).Date }}, `
EventID, Source, Message | Sort-Object @{e='Date';Descending=$True}, @{e='EventID';Ascending=$True}
$Temp = @()
ForEach ($Object in ($Entrees | Select-Object -Property Date, EventID, Source, Message -Unique)) {
$Temp += $Object | Select-Object *, `
@{n='Count';e={ $Entries = $Entrees | ?{ $_.EventID -eq $Object.EventID -And $_.Date -eq $Object.Date }; `
If ($Entries.Count) { $Entries.Count } Else { 1 } } }
}
$Entrees = $Temp
If ($Entrees) {
Echo $log.LogDisplayName
Echo "------------------------------------------------------------------------------"
# Pick the first 10 in the list (will be the most recent)
$Entrees | Select-Object -First 10 | FT -Wrap $Format
}
}
}
|