cd C:Eventlog $gap = (Get-Date) - (New-TimeSpan -Days 365) $unusedfiles = Get-ChildItem | where -FilterScript {$_.lastwritetime -lt $gap -and $_.name -ne "eventsave.exe"} | select -ExpandProperty Name ForEach ($unusedfile in $unusedfiles) { Remove-Item $unusedfile }