Delete files older than x-number of days – PowerShell

Delete files in a directory that are older than x number of days.

Sometimes there’s a need to delete files that are older than a certain number of days, months, or years. This is especially true when creating scheduled jobs to clean up server logs, old cached files, etc.

This simple script can be ran to do so, just edit the number of days and the targeted directory.

Once specifying the folder and number of days, this script can be ran or scheduled- perfect for clean-up tasks.

 

Leave a Reply

Your email address will not be published.