Pokud potřebujete smazat soubory starší než x dní. Skript má 3 parametry: cesta, filtr souborů, počet dní.
if ($args.length -ne 3) {
„This script takes exactly THREE arguments, in this order: a path to analyze, a filter .txt, a number of days to keep files“
}
else {
$path = $args[0]
$filter = $args[1]
$days = $args[2]
$recurse = $true
$confirm = $false
get-ChildItem -Path $path -Include $filter -recurse:$recurse | where {$_.LastWriteTime -le $(get-date).AddDays(-$days)} | Remove-Item -Force -Confirm:$confirm
}