Administrators often have to stifle through Windows logs to troubleshoot problems with their systems or applications. However, manually going through heaps of system log information is laborious. The following PowerShell script, when executed, will return the most recent error messages within a specific number of logs.
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