PowerShell public

Windows Event Errors

Share this script safely, inspect its metadata, and copy the exact command you need.

Dashboard

Ready to run

One-liner

Copy the command, then review before execution.
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

Slug
QGV580RWYG01
Fetches
0
Size
1745 B · 64 lines
Expires
never
Last fetch
Created
2026-09-07 00:36:00.746
Description
Error and critical events from the last 24 hours

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.

Restore revision