PowerShell: Reading the Event Log with Get-EventLog

What It Is For

The Windows event log is where a machine tells you what happened: service crashes, disk warnings, application errors, driver problems. Reading it by clicking through Event Viewer is slow, and worse, it gives you one event at a time when the useful information is the pattern.

Get-EventLog turns the log into objects you can filter, group and count. That is the difference between "there is an error" and "the same service has logged this 47 times this week".

One important caveat up front: Get-EventLog is a Windows PowerShell cmdlet that does not exist in PowerShell 7+. On the modern shell you want Get-WinEvent. I use Get-EventLog where it is available because the syntax is friendlier, and reach for Get-WinEvent when I need performance or newer logs. Both are covered below.

A photorealistic shot of a laptop showing a PowerShell console with a table of event log entries, a Windows Event Viewer window open behind it, office desk, daylight, realistic photography, no legible text.

The Basic Read

$Event = Get-EventLog -LogName System -Newest 1000
$Event

Application instead of System for the application log. -Newest 1000 is fine interactively, and it is a poor basis for anything you run regularly — it is an arbitrary slice, not a time window.

Grouping, Which Is Where The Value Is

Raw events are noise. Your own system's noise profile is the signal:

$Event | Group-Object -Property Source -NoElement | Sort-Object Count -Descending | Format-Table *

That gives you counts by source, largest first. Run it on a healthy machine and then on one with a problem and the difference is usually obvious — and it tells you where to look instead of scrolling.

-NoElement matters: without it, PowerShell keeps every event object inside each group, which is slow and memory-hungry on a 1,000-entry set. Add it unless you are going to inspect the members.

A Time Window, Which Is The Useful Version

-Newest is not a good filter for a scheduled report. A date range is:

$Date = (Get-Date).AddDays(-7)
$Event = Get-EventLog -LogName System -After $Date -EntryType Error, Warning
$Event | Group-Object -Property Source -NoElement | Sort-Object Count -Descending | Format-Table *

Two syntax notes, because both are easy to get wrong:

-EntryType Error, Warning — the parameter is -EntryType, hyphenated, and the values are comma-separated after it. Writing -After $Date EntryType Error puts the word EntryType in as a positional argument and the command fails.

-Before and -After take a [DateTime], not a formatted string. Pass (Get-Date).AddDays(-7), not '2026-11-05'.

Writing It Out

$Stamp = Get-Date -Format 'yyyy-MM-dd'
$Event | Group-Object -Property Source -NoElement |
    Sort-Object Count -Descending |
    Format-Table * |
    Out-File -FilePath "C:\Logs\SystemErrors-$Stamp.txt"

Get-Date -Format 'yyyy-MM-dd' uses a standard .NET format string. The original version of this snippet used -Format FileDate, which is not a valid format token and silently produces something unexpected — use an explicit pattern so the filename sorts correctly.

Also note Out-File writes UTF-16LE by default in Windows PowerShell, which some tools cannot read. Add -Encoding utf8 if the file leaves the machine.

Get-WinEvent, For Anything Modern

Where Get-EventLog is unavailable, or when you need the newer logs:

# same idea: errors and warnings from the last day, grouped by provider
Get-WinEvent -FilterHashtable @{LogName='System'; Level=1,2,3; StartTime=(Get-Date).AddDays(-1)} |
    Group-Object ProviderName | Sort-Object Count -Descending | Format-Table Count, Name

-FilterHashtable is dramatically faster than Where-Object filtering, because the filtering happens inside the event API rather than after every event has been loaded into memory. On a busy server this is the difference between two seconds and two minutes.

Level numbers: 1 critical, 2 error, 3 warning.

A photorealistic close-up of a monitor showing a PowerShell table with counts and source names, a notebook with a short list of service names written beside it, warm desk light, realistic photography, no legible text.

A Sanity Check Worth Doing

Before you trust a number, confirm the log is not just small:

Get-EventLog -List | Format-Table Log, MaximumKilobytes, OverflowAction, Entries -AutoSize

If OverflowAction is OverwriteAsNeeded and the log has already wrapped, your "last 7 days" is really whatever fits — you may silently be looking at two days. That single check has saved me from drawing conclusions from a truncated history more than once.

A photorealistic shot of a monitor showing a plain text report file with a short list of event counts, a coffee cup beside the keyboard, morning light through a window, realistic photography, no legible text.

Practical Use

The version I actually keep as a scheduled job: pull errors and warnings from the last 24 hours, group by source, and write a small summary file. Every morning it either says nothing interesting or points at the one service that started misbehaving. That is a better error signal than any dashboard, because it is derived from the machine's own view of itself.

Don't trust the download button. Trust the hash.

If this was useful, More hands-on tech guides at TechGeek. No pressure — read it whenever it's useful.


Luke Keam
Spot a bug or want a custom utility built? I'd love to hear from you. Get in touch
Luke Keam | techgeek.biz