Delete files from folder (and subfolders) based on timestamp

$Path = “D:\WSUS\WsusContent\”
$Daysback = “-1000”

$CurrentDate = Get-Date
$DatetoDelete = $CurrentDate.AddDays($Daysback)
Get-ChildItem $Path -Recurse | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item

Leave a Reply

Your email address will not be published. Required fields are marked *