Event log html output with colorized rows RRS feed

  • Question

  • I am trying to extract certain error and warning events for a bunch of servers and have the output corlorized in html where red rows are for errors and yellow rows are for warnings.  The code below works mostly.  That is most of the rows are colorized but some are white with only the correct word red or yellow in the right most column.  Any idea why all the rows are not being colorized?

    #define events you are NOT interested in seperated by a ","
    #List Below all the Event ID's you do not want reported in SYSTEM Event Log
    $SYS_EXCL_events = @(1,3,4,8,1103,1111,1124,7000)
    #List Below all the servers you want to check for ERRORS in the SYSTEM and APPLICATION logs
    $Servers = @("Enterprise","Bigguy","Galaxy","Security")
    #Get System Event Errors except for those listed in $SYSevents above
    $SysEvent = get-EventLog -logname System -newest 2000 -ComputerName $Servers | where-object {$SYS_EXCL_events -notcontains $_.eventid} 
    $SysError = $SysEvent | where {$_.entryType -match 'Error' -or $_.entryType -match 'Warning'} 
    $html = $SysError | Add-Member -MemberType ScriptProperty -Name RowColor -Value {if ($this.entrytype -match 'Warning') {[System.ConsoleColor]::Yellow} else {[System.ConsoleColor]::Red}} -PassThru | Select-Object TimeWritten,EventID,MachineName,EntryType,Source,Message,RowColor | ConvertTo-Html
    foreach ($consoleColor in @([System.ConsoleColor]::Yellow,[System.ConsoleColor]::Red)) {
    $html = $html -replace '<th>RowColor</th>','' -replace "<tr>(.*)<td>$consoleColor</td></tr>","<tr bgcolor=$($consoleColor.ToString().ToLower())>`$+</tr>"
    $html | Out-File C:\Test.htm
    Send-MailMessage -To '' `
    -From '' -SmtpServer 'Galaxy.cpsiinc.local' -Subject 'System Event Log Errors & Warnings' -Body 'See attached' -Attachments C:\Test.htm

    Thursday, October 3, 2013 8:13 PM