How to automatically delete files older than X days using PowerShell

How to automatically delete files older than X days using PowerShell

HomeGuides, How to, TechHow to automatically delete files older than X days using PowerShell

You can use PowerShell to free up space and keep things organized by deleting only files older than a certain number of days in all folders. Here's how to do it in Windows 10.

ChannelPublish DateThumbnail & View CountActions
Channel Avatar Newbie Computer2021-09-06 02:48:43 Thumbnail
23,279 Views

Task Scheduler: How to automatically delete files older than X days – Windows Command Prompt

In Windows 10, Storage Sense is a feature that automatically frees up storage space when you're running low. The feature deletes junk system files—files that have been in the Recycle Bin or Downloads folder for more than a month—and makes OneDrive content you've been using for a while available only online.

While this feature can be helpful for controlling storage space, it is limited and does not provide a way to manually add different locations to monitor and delete files that have not changed in the last month. If you store non-important files elsewhere, you can use PowerShell and Task Scheduler to monitor and clean files from any folder that is older than a certain number of days.

This guide will show you how to automatically delete files in Windows 10 that haven't been modified in the last month or within a number of days you specify. (These steps should work in Windows 11 too.)