functions/Remove-OldDownloads.ps1
Function Remove-OldDownloads { <# .SYNOPSIS This script will remove files older than x days within Redirected Downloads Folders Set PATH to the top level Redirected folder (e.g. D:\RedirecedFolders) .EXAMPLE Remove-OldDownloads -Path D:\RedirectedFolders -Days 14 #> [CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [Parameter(Mandatory = $true)] [int]$Days ) Get-childitem $Path -Depth 1 -Directory -Filter "Downloads" | Get-ChildItem -Recurse -Force -Exclude *.ini | Where LastWriteTime -LT (Get-Date).AddDays(-$Days) | Remove-Item -Force -Recurse -Verbose } |