PowerShell Script to Delete Files Older Than 30 Days
To delete files older than 30 days with PowerShell, list the files with Get-ChildItem, keep the ones whose LastWriteTime is before a cutoff date, and pipe them to Remove-Item. Run it with -WhatIf first: Output: In a real script, set the cutoff with (Get-Date).AddDays(-30). I used a fixed date and a sample folder so the … Read more