Tip: You can clear all the events logs (Windows Logs + Application and Services Logs)
1 2 3 4 5 6 7 |
# Solution 1 (faster) Get-WinEvent -ListLog * | ForEach-Object -Process { [System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog($_.LogName) } # Solution 2 (slower) wevtutil.exe el | ForEach-Object -Process { wevtutil.exe cl "$_" } |
The solution 1 is faster than the solution 2.
I clear all the event logs and created 500 000 events on Application, System and Windows Powershell logs.
1 2 3 4 5 6 |
for ($i = 1; $i -le 500000; $i++) { Write-EventLog -LogName Application -Source Perflib -EventId 1008 -Message 'This is a test event.' Write-EventLog -LogName System -Source W32Time -EventId 29 -Message 'This is a test event.' Write-EventLog -LogName 'Windows PowerShell' -Source PowerShell -EventId 601 -Message 'This is a test event.' } |
Solution 1 (GlobalSession.ClearLog) : 0.64 seconds
Solution 2 (wevtutil) : 4.6 seconds