Написал простенькую универсальную функцию.
Function Del-Old{
Param(
#target path. Enter one string
$TargetPath,
#Enter one or many (array) exclude files (just names, not full address)
$ExcludePath = @(),
#Enter number of life time hours objects. Oldest objects will delete
[int]$TimeLifeHours
)
$TimeLimit = (Get-Date).AddHours(-$TimeLifeHours)
$ObjectsForDel = dir -Path $TargetPath -Exclude $ExcludePat | ?{$_.CreationTime -lt $TimeLimit}
foreach ($obj in $ObjectsForDel){
del -Path $obj.FullName -Recurse
}
}