Color coding the output

Hi,

This is small script to get events after last reboot and color code the output depending on it’s error event or not

Function getlastreboottime{
(get-eventlog -LogName System | where {$_.EventID -eq ‘1074’} | select -First 1).TimeGenerated
}

Function GetEventsAfterLastReboot($time){
get-eventlog -LogName System -After $time
}

$LastRebootime = getlastreboottime
Write-host The system was last reboot on $LastRebootime -ForegroundColor Green
$events = GetEventsAfterLastReboot($LastRebootime)
Write-Host Following events after last reboot. The error evens are marked in RED -ForegroundColor Green

foreach ($event in $events){
if ($event.entrytype -eq ‘Error’){
write-host $event -ForegroundColor red
}
else {(write-host $a -ForegroundColor Green)
}
}

But this is the output… It is not displaying the the event details

please help me.

The system was last reboot on 13-05-2020 18:20:31
Following events after last reboot. The error evens are marked in RED
System.Diagnostics.EventLogEntry
System.Diagnostics.EventLogEntry
System.Diagnostics.EventLogEntry

 

 

 

$event is an object not a text string

Function getlastreboottime{
    (get-eventlog -LogName System | where {$_.EventID -eq ‘1074’} | select -First 1).TimeGenerated
}

Function GetEventsAfterLastReboot($time){
    get-eventlog -LogName System -After $time
}

$LastRebootime = getlastreboottime
Write-host The system was last reboot on $LastRebootime -ForegroundColor Green
$events = GetEventsAfterLastReboot($LastRebootime)
Write-Host Following events after last reboot. The error evens are marked in RED -ForegroundColor Green

foreach ($event in $events){
    if ($event.entrytype -eq ‘Error’){
        write-host ($event|FL *|Out-String).Trim() -ForegroundColor red
    }
        else {(write-host $a -ForegroundColor Green)
    }
}