Display the most recent error messages in the system logs

To display the error messages in the most recent x number of logs, where x is a parameter value supplied in the script.

Script

<#
.SYNOPSIS
This script can be used to display the error messages in the most recent x number of logs.
.DESCRIPTION
This script can be used to display the error messages in the most recent x number of logs.
.EXAMPLE
C:\PS> C:\Script\System_Error_Logs.ps1 100
Displays the Error messages in most recent 100 logs.
#>

param ( [int]$count )
#Gets the newest x number of event logs.

$Event = Get-Eventlog -Logname system -Newest $count
#Filters errorlogs in the newest x number of event logs.

$Error = $Event | Where {$_.entryType -Match “Error”}
$Error | Sort-Object EventID |Format-Table EventID,Source,TimeWritten,Message -auto

 

Output
ErrorLogs

Leave a Reply