Level Verified

Windows Event Log Monitor Script

Searches Windows event logs for specific event IDs, severities, and sources. If matching events are found within the defined timeframe, it triggers an alert, making it easier to catch critical or error-level events in real time.

Import into Level

Problem overview

Monitoring Windows event logs can be daunting, especially when you need to isolate specific error or warning occurrences. Missed events can quickly escalate into unresolved issues, leading to service disruptions, user complaints, or system crashes. This script pinpoints crucial log entries automatically, helping IT professionals identify and respond to problems before they spread.

PowerShell 100s timeout Runs as Local system Windows
<#
This resource is provided as a convenience for Level users. We cannot 
guarantee it will work in all environments. Please test before deploying 
to your production environment. We welcome contributions to our community 
library

Level Library
https://level.io/library/script-windows-event-log-monitor
#>


#Chose which event log to monitor: application, security, or system
$LogName = "application"

#Chose which event ID to monitor.
$ID = 1000

#Chose the severity level of the event. (Critical 1, Error 2, Warning 3, 
#Informational 4) Can be comma seperated list (don't use quotes)
$EventSeverity = 2

#Chose the provider name (source) of the event.
$ProviderName = "Application Error"

#Chose the timeframe (in minutes) in which to search.  Search the logs filtered 
#to the past X minutes.  This should be synced up with the monitor run 
#frequency.  If the frequency will be set to checking every 5 minutes, then the
#timeframe shouldn't exceed that.
$Timeframe = 5


$TimeSpan = (Get-Date) - (New-TimeSpan -Minutes $Timeframe)
$ErrorActionPreference = 'silentlycontinue'

#Pull the events and filter them
$EventTracker = Get-WinEvent -FilterHashtable @{
    LogName      = $LogName
    ID           = $ID
    Level        = $EventSeverity
    ProviderName = $ProviderName
    StartTime    = $TimeSpan
} -MaxEvents 10

#Display the events
$EventTracker

#If there are events that match, trigger the ALERT
if ($EventTracker) {
    Write-Output "ALERT"
    exit 1
}
else {
    Write-Output "Events not found.  Check your filter variables if you are expecting a match."
    exit 0
}

This script filters the specified Windows event log—whether Application, Security, or System—for event IDs, severity levels, and provider names you define. It also allows you to focus only on events within a designated timeframe, ensuring timely and relevant alerts. If matching entries are found, the script triggers an alert exit code (1), facilitating an automated response or investigation through Level’s integrated monitoring and alerting features.

Use cases

  • Pinpointing recurrent crash events from a specific application
  • Tracking security or system warnings within critical timeframes
  • Identifying serious application errors before they impact end users
  • Triggering alert-driven automations for immediate incident response

Recommendations

  • Configure a script-based monitor in Level to run at intervals matching your timeframe setting
  • For recurring checks, create an automation in Level with a scheduled trigger that runs this script to regularly scan event logs
  • Test in a non-production environment to confirm correct event filtering and avoid false positives
  • Update the script variables (LogName, ID, EventSeverity, ProviderName, Timeframe) to suit your specific monitoring needs
  • Keep an eye on performance by limiting the timeframe and maximum events to reduce overhead on busy systems

Frequently asked questions.

Can I monitor multiple event IDs at once?

Not in the current script version. You can adapt it to search multiple IDs or run separate instances for each ID.

Does this script attempt any remediation actions?

No, it only scans the event logs and exits with an alert if matching events are detected. Use separate scripts or automations for repairs.

Can I modify the event provider name to match third-party apps?

Absolutely. Change the $ProviderName variable to filter any desired source.

Will this script work on older Windows OS versions?

It depends on the availability of Get-WinEvent. It’s supported on most modern Windows environments, but test for compatibility.

Can I increase the timeframe to a longer window?

Yes, but ensure it aligns with the frequency of your monitor or scheduled task in Level to avoid overlapping or missing events.

Ready when you are.

No credit card. No sales call. Just sign up and start managing.