Delete files older than X

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche

Dateien die älter als 60 Tage sind -> löschen

# Delete all Files in <Path> older than 60 days
 
$Path = "<C:\Path>"
$Daysback = "-60"
$CurrentDate = Get-Date
$DatetoDelete = $CurrentDate.AddDays($Daysback)
 
Get-ChildItem $Path -Recurse | Where-Object {$_.LastWriteTime -lt $DatetoDelete} | Remove-Item -Force -Recurse