Clear Up All Events from Event Logs The Easy and PowerShell Way


Normally, when we need to check the event logs on our computer, we would go to Event Viewer, select one type of the logs, and go through them. When we need to clear up any of them, we would right-click on them, and choose Clear Log…, and we would do each one of them separately. A little bit tedious, isn’t it?

Clear Up Event Log

It would be nice if I can just clear all them up in one shot. And luckily we have PowerShell to help, and why not using it?

The cmdlet Get-EventLog could be used to retrieve a list of event logs, with option -List.

Get-EventLog -List

And then use Clear-EventLog cmdlet to clear all them up:

Clear-EventLog -LogName (Get-EventLog -List).log

Note that in order to execute it successfully, you will need to open your PowerShell Console as Administrator.

Actually, if you look more, there are a lot more you can do with your Event Log with these Event Log related PowerShell cmdlets. For example,

Combining with the basic filter feature, you can find a specific type of logs. Such as, running the following cmdlet returns all event logs labelled as Error.

Get-EventLog -LogName System | ? EntryType -eq Error

Or, you can use the cmdlet New-EventLog to create a new event log, i.e. your own type for your own application, whether on your local computer or a remote machine.

Or, you can use Limit-EventLog to configure your existing event logs, e.g. the maximum size of a classic event log, how long each event must be retained, and what happens when the log reaches its maximum size.

Or, you can even use Write-EventLog to write an event to an specified event log. Such as, running this

Write-EventLog -LogName System -Source EventLog - EntryType Information - Message "Good Work, Kent" -EventID 0

I got this:

Event Viewer - 2014-02-07 14_07_46



Please enter your comment!
Please enter your name here