PowerShell: Clear Event logs from Windows machine

Problem Statement:

Need to clear off Application, Security and System Event logs of your Windows PC? Well here’s the solution.

[sourcecode language="powershell"]
foreach($computer in $args)
$ALive=get-wmiobject win32_pingstatus -Filter "Address='$computer'" | Select-Object statuscode
if($ALive.statuscode -eq 0)

$logs = [System.Diagnostics.Eventlog]::GetEventLogs("$computer")
$Applogs = $logs|where-object {$_.logdisplayname -eq "Application"}
$Securitylogs = $logs|where-object {$_.logdisplayname -eq "Security"}
$Systemlogs = $logs|where-object {$_.logdisplayname -eq "System"}
write-host Event logs cleared at $computer -background "GREEN" -foreground "BLACk"
sleep 1
write-host $computer is NOT reachable -background "RED" -foreground "BLACk"
write-host "`nCheck if the system is Online `n"
sleep 1

The Script requires computer ip or computer names passed as Command Line Arguments.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.