С рекурсивным обходом папок
$now = Get-Date $date = $now.AddMonths(-1) $files = Get-ChildItem -Path C:\Log -recurse | Where {$_.LastWriteTime -le "$date"} foreach ($file in $files) { write-host "Deleting File $file" -foregroundcolor "Red"; Remove-Item $file # для теста добавить -whatif }
gci ‘E:\IIS Logs’ -Directory | gci -Include ‘*.log’,’*.blg’ -Recurse | ? LastWriteTime -lt (Get-Date).AddDays(-30) | Remove-Item