brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Get-WinEvent -FilterHashtable shows only the errors from the last day

Windows
~/tips/tip-windows-get-winevent-filterhashtable

Get-WinEvent -FilterHashtable @{LogName='System'; Level=1,2; StartTime=(Get-Date).AddDays(-1)}

Pulls only recent critical and error events from a Windows log, without opening Event Viewer.

Event Viewer works, but clicking through it to find what went wrong last night is slow. I’d rather ask PowerShell for exactly the events I care about.

Get-WinEvent -FilterHashtable @{LogName='System'; Level=1,2; StartTime=(Get-Date).AddDays(-1)}

That gives you the critical (1) and error (2) events from the System log of the last 24 hours, newest first. Level 3 is warning and 4 is informational. Use the numbers, as the Microsoft docs do.

Other keys you can put in the hash table include ProviderName, ID, EndTime and Path for a saved .evtx file. Looking for one specific event ID is a matter of adding ID= with that number.

To keep it short, add -MaxEvents:

Get-WinEvent -FilterHashtable @{LogName='Application'; Level=2} -MaxEvents 20 |
  Format-Table TimeCreated, ProviderName, Id, Message -Wrap

I prefer the hash table over piping everything into Where-Object: the whole question sits in one place, and Get-WinEvent hands back only what matches.

Caveats. Wildcards only work in the LogName and ProviderName values, and each key can be used once per table. And the docs say the cmdlet is only available on Windows.

Further reading: Get-WinEvent on Microsoft Learn, Creating Get-WinEvent queries with FilterHashtable, On this site: sfc /scannow repairs corrupted Windows system files

More Windows tips Win+Ctrl+C Win+Shift+Left arrow Win+Ctrl+Left arrow Alt+PrtScn Left Alt + Left Shift + Print Screen All Windows tips (33) All topics

Link