Although this feature can be helpful to control the storage space, it is limited and doesn’t offer an option to manually add different locations to monitor and delete files that haven’t changed in the last month or so. If you store non-important files in a different location, it is possible to use PowerShell and Task Scheduler to monitor and clean up files from any folder older than a specified number of days. In this guide, you will learn the steps to automatically delete files that haven’t been modified in the last month or any number of days you specify on Windows 10. (These steps should also work on Windows 11.)

Delete files older than X days on Windows 10 using PowerShell Delete files older than X days automatically on Windows 10 using Task Scheduler Delete files older than X days automatically using Command Prompt

Delete files older than X days on Windows 10 using PowerShell

If you have different folders with a lot of files and you would like to clean up by deleting those older than certain days, you can use these steps:

Delete files older than X days automatically on Windows 10 using Task Scheduler

The command in the previous instructions allows you to delete files in a folder older than 30 days, but you need to open PowerShell and execute the command manually every time you want to free up space. Change the path: “C:\path\to\folder” with the folder location, you want to delete files and change -30 to select files with a last modified date in the above command.

Create PowerShell script using Notepad

To run a task using the Task Scheduler, you’ll need to create a PowerShell script with the steps:

Create task using Task Scheduler

If you want to automate the process, you need to use the Task Scheduler to create a task that executes the command at specified intervals. Change this path: “C:\path\to\folder” with the folder location, you want to delete files and change -30 to select files with a last modified date in the above command. Once you complete the steps, the PowerShell script will run on the schedule deleting the files older than the number of days you specified. Remember not to change the name or move the folder to another location. Otherwise, the task will fail.

Change the path: “C:\path\to\cleanup.ps1” with the PowerShell script location you have previously created to delete files in the command.

Allow task to be run on demand. Run task as soon as possible after a scheduled start is missed. If the task fails, restart everything.

		      All content on this site is provided with no warranties, express or implied. Use any information at your own risk. Always backup of your device and files before making any changes. Privacy policy info.