PowerShell: Find Events by Time Range

Need to check what happened during a specific window of time - narrowing down when an issue started, or reviewing activity from a particular day? This one-liner filters events between two timestamps.

Prerequisites:

  • Privileges: None (for System and Application logs; Security log requires Administrator)
  • Module: Built-in, no import needed

Quick Command:

Get-WinEvent -FilterHashtable @{LogName='System'; StartTime=(Get-Date).AddDays(-1); EndTime=(Get-Date)} -MaxEvents 5

Example Output:

ProviderName: Microsoft-Windows-DistributedCOM
TimeCreated                     Id LevelDisplayName Message
-----------                     -- ---------------- -------
7/27/2026 12:44:20 PM         10016 Warning         The machine-default permission settings do not grant Local...
7/27/2026 12:44:20 PM         10016 Warning         The application-specific permission settings do not grant...
📦
Want all of them at once?
Get every free one-liner from this blog in a single downloadable bundle organized by category, each with full comment-based help. No more copy-pasting one at a time.

How It Works:

  • StartTime=(Get-Date).AddDays(-1) sets the beginning of the time window to exactly 24 hours before right now - (Get-Date) gets the current date and time, and .AddDays(-1) subtracts one full day from it.
  • EndTime=(Get-Date) sets the end of the window to the current moment - together with StartTime, this creates a rolling "last 24 hours" filter.
  • -MaxEvents 5 limits the output to the most recent matches within that time window.