POWERSHELL – DELETE OLD FILES
Overview We can delete files older than X days. We can create a scheduled task to run the PowerShell script on a schedule. List Files To Delete
1 |
Get-ChildItem -Path "C:\SomePath\Folder" -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.Lastwritetime -lt (Get-Date).AddDays(-8) } |
This code uses the Get-ChildItem and Where-Object cmdlets to search for all…