Technology Toolbox

Your technology Sherpa for the Microsoft platform

Jeremy Jameson - Founder and Principal



PowerShell Script for Clearing Windows Event Logs

A couple of years ago, I shared the script I created to quickly clear the event logs on a server (but saving them first -- just in case I need to go back and retrieve something from the "archive").

While that script (Clear Event Logs.vbs) is still in my Toolbox, I can't remember the last time I used it. This is largely due to the fact that I primarily use Server ManagerDiagnosticsEvent ViewerCustom ViewsAdministrative Events to quickly check on the health of my development VMs, and with the introduction of the Applications and Services Logs in Windows Server 2008, running that script doesn't always clear everything in that view.

For example, after running:

cscript "Clear Event Logs.vbs"

...I would still see lots of warnings in the Administrative Events view from TerminalServices-PnPDevices.

Consequently I switched over to using PowerShell to clear all the event logs -- not just the "classic" event logs (i.e. Application, Security, and System).

I started out by simply typing the following in a PowerShell window:

wevtutil el | % { wevtutil cl $_ }

However, typing that command even once every few days quickly grew tiresome, so I wrapped it up in a script in my Toolbox. Now I simply run the following to clear the event logs on a development VM:


Unlike "Clear Event Logs.vbs", Clear-EventLogs.ps1 does not save the event logs before clearing them. If you desire to maintain that functionality, then you'll need to modify the script accordingly.

Personally, I haven't found the need for doing that since I only clear the event logs on development VMs (System Center Operations Manager "barks at you" when you clear the event logs on servers that are being monitored -- e.g. the Production environment at Technology Toolbox).


You can download this script from my Toolbox repository on GitHub:


Clears all Windows event logs.

Clearing all of the Windows event logs is useful in development environments
(for example, to check if a computer reboots "cleanly" -- i.e. without any


This script must be run with administrator privileges.

Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

wevtutil el | ForEach-Object { wevtutil cl $_ }



No comments posted yet.

Add Comment

Optional, but recommended (especially if you have a Gravatar). Note that your email address will not appear with your comment.
If URL is specified, it will be included as a link with your name.

To prevent spam from being submitted, please select the following fruit: Cherries

Please add 7 and 4 and type the answer here: