Networknet archive Blog

PowerShell: Clear Windows event logs

Originally published Last updated

My previous post covered clearing Windows event logs. I have now ported the script to PowerShell. While developing a Windows 7 WIM image, I wanted to clear the logs after restoring the image. I already use several PowerShell scripts, so adding this command gave me a clean set of logs.

Requirements

  • Open PowerShell with elevated privileges on Windows 7.
  • Create a ps1 file using the script below.

Script

Code1 line
1
 $logs = wevtutil el $logs | foreach-object {invoke-expression -command "wevtutil cl '$_'"}

References