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?
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.
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:
Latest posts by Kent Chen (see all)
- The Story of How SSH Got the Port Number 22 - April 28, 2017
- Microsoft To-Do App Available in Preview on Windows 10, iOS and Android - April 19, 2017
- Windows 10 Tip: What’s Mini View in Movies & TV App and How To Use it - April 15, 2017
Last updated: 08/04/2014