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.

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s