删除一年之前的日志文件

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
}
原文地址:https://www.cnblogs.com/IvanChen/p/4493770.html