Category Archives: PowerShell
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"} $Applogs.clear() $Securitylogs = $logs|where-object {$_.logdisplayname -eq "Security"} $Securitylogs.Clear() $Systemlogs = $logs|where-object {$_.logdisplayname -eq "System"} $Systemlogs.Clear() write-host Event logs cleared at $computer -background "GREEN" -foreground "BLACk" sleep 1 } else { 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.