Cleanup Older than 30 days of Files & Folder through SQL Job

,

If you have a requirement to cleanup older than 30 (or any number of days), days of folders and files from any designated location, you can do it via SQL Server Agent Job.

Just setup the job with Type as "PowerShell" and paste my code.

Configure and run it.

Ensure that you have powershell 2.0 configured.

Get-ChildItem "D:\backups\"  -force -recurse | where-object {$_.LastWriteTime -le (Get-Date).AddDays(-30) -and !$_.PsIsContainer} | remove-item -force;

Rate

5 (1)

Share

Share

Rate

5 (1)