October 6th, 2013

PowerTip: Use PowerShell to Find Event Logs with Events

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to find all event logs that contain events.

Hey, Scripting Guy! Question How can I use Windows PowerShell to find all traditional and non-traditional event logs that contain events?

Hey, Scripting Guy! Answer Use the Get-WinEvent cmdlet to return all event logs, use Where-Object to filter the logs that
         contain more than 0 records, and sort the results:

In Windows PowerShell 4.0 and Windows PowerShell 3.0:

Get-WinEvent -ListLog * | where recordcount -gt 0 | sort recordcount

In Windows PowerShell 2.0:

Get-WinEvent -ListLog * | where {$_.recordcount -gt 0} | sort recordcount

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.