PowerShell
public
Windows Event Errors
Share this script safely, inspect its metadata, and copy the exact command you need.
Ready to run
One-liner
curl -fsSL https://runny.sh/r/QGV580RWYG01 | pwsh
Current version: 1.1 · Updated by Godmode · 2026-09-07 02:38:59.517
At a glance
Script metadata
Readable before runnable
Preview
# Windows event errors
# Read-only: Get-WinEvent Error/Critical from Application and System in the last 24h (top 20).
# Exit 0 if current, 1 if errors exist, 2 on query failure.
# Hosted on Runny.sh. Review the script page before you run it.
$ErrorActionPreference = 'Continue'
$status = 0
function Write-Line {
param([string]$Text)
Write-Output $Text
}
function Set-Warn {
if ($script:status -lt 1) { $script:status = 1 }
}
Write-Line '=== Windows Error/Critical events (24h) ==='
Write-Line ("Host: {0}" -f $env:COMPUTERNAME)
Write-Line ''
$filter = @{
LogName = @('Application', 'System')
Level = 1, 2
StartTime = (Get-Date).AddHours(-24)
}
try {
$events = @(Get-WinEvent -FilterHashtable $filter -MaxEvents 20 -ErrorAction Stop)
} catch {
if ($_.Exception.Message -match 'No events were found') {
$events = @()
} else {
Write-Line 'Get-WinEvent failed'
Write-Line $_.Exception.Message
Write-Line 'Result: ERROR'
exit 2
}
}
Write-Line ("Shown: {0} (capped at 20)" -f $events.Count)
if ($events.Count -eq 0) {
Write-Line ' none'
Write-Line ' OK'
} else {
foreach ($evt in $events) {
$when = $evt.TimeCreated.ToString('yyyy-MM-dd HH:mm')
$level = $evt.LevelDisplayName
$msg = ($evt.Message -replace '\s+', ' ')
if ($msg.Length -gt 120) { $msg = $msg.Substring(0, 119) + '...' }
Write-Line (" - {0} {1} {2}/{3} {4}" -f $when, $level, $evt.LogName, $evt.Id, $msg)
}
Set-Warn
}
Write-Line ''
if ($status -eq 0) {
Write-Line 'Result: CURRENT'
} else {
Write-Line ("Result: ACTION NEEDED ({0} recent Error/Critical event(s))" -f $events.Count)
}
exit $status
Raw endpointhttps://runny.sh/r/QGV580RWYG01
See something unsafe?
Report this script
Tell us why it should come down. Anyone can also report a URL at /abuse.