Color coding the output

Welcome Forums General PowerShell Q&A Color coding the output

Viewing 1 reply thread
  • Author
    Posts
    • #228394
      Participant
      Topics: 1
      Replies: 0
      Points: 14
      Rank: Member

      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

       

       

       

    • #228421
      Participant
      Topics: 12
      Replies: 542
      Points: 1,319
      Helping Hand
      Rank: Community Hero

      $event is an object not a text string

Viewing 1 reply thread
  • The topic ‘Color coding the output’ is closed to new replies.