1
votes

I need to count how many error events are logged under "Application" and "System" of a remote computer using powershell. I have started this but not got to far.

Get-EventLog -computername COMPUTER -Logname Application -EntryType Error | Measure-Object -Sum Entrytype | Format-Table Count

This is very rough right now and the two problems so far is that the above command only does ONE type of log at a time, and the format of the table isnt very useful.

Id like to have extra headers so it outputs Computername, Entrytype and Count.

How can I get powershell to list both events and have extra headers with the table?

3

3 Answers

1
votes

For a quick display of error count per log file:

$filter = "LogFile='application' OR LogFile='system' AND EventType=1"

Get-WmiObject Win32_NTLogEvent -ComputerName COMPUTER -Filter $filter -Property  ComputerName,LogFile,EventType | `
  Group-Object -Property LogFile -NoElement
1
votes
$info  = foreach ($log in "application", "system") {get-eventlog -ComputerName $computername -LogName $log -EntryType error }
$groupedinfo = $info | group-object machinename, entrytype
$groupedinfo | select @{N="Computername";E={$_.name.split(',')[0]}},
                      @{N="EntryType";E={$_.name.split(',')[1]}},
                      count
-1
votes

A sample of what I use, for the count bit at least, because it is dirty and quick on a single line:

$EventCount=0; Get-EventLog -LogName "Application" -EntryType "Information" | foreach{$_;$EventCount++}|Out-Null;"Total Events is:"+$EventCount

The out-null simply stops useless info, in this case, spewing onto the screen.