![]() Type the following command in the “Add arguments” setting and click the OK button: -ExecutionPolicy Bypass C:\path\to\cleanup.ps1Ĭhange the “C:\path\to\cleanup.ps1” path with the PowerShell script location you have previously created to delete files in the command. Type the following command in the “Program/script” setting: powershell.exe Select the “Start a program” option in the “Actions” setting. Whatever option you select, specify the Start settings on the right side. ![]() Under “Settings,” specify when to run the task (for example, On time, Daily, Weekly, Monthly). Select the “On a schedule” option in the “Begin the task” setting. (This option will make the command window not appear when the task runs automatically.)Ĭlear the “Do not store password” option. Under the “General” tab, under the “Security options” section, select the “Run whether user is logged on or not” option. Right-click the folder and select the Create Task option.Ĭonfirm a name for the task in the “Name” setting. (Optional) Right-click the “Task Scheduler Library” folder and select the New Folder option.Ĭonfirm a name for the folder and click the OK button. Search for Task Scheduler and click the result. To run the PowerShell script automatically to delete old files with Task Scheduler, use these steps: Save the file using the cleanup.ps1 name and extension. In the command, change this “C:\path\to\folder” path with the folder location and “-30” for the age of the file since the last modification. Type the following command to delete files that haven’t been modified in the last 30 days and press Enter: Get-ChildItem –Path "C:\path\to\folder" -Recurse | Where-Object | Remove-Item Search for Windows PowerShell, right-click the result, and select the Run as administrator option. To delete older files from a specific location on Windows 10, use these steps: Delete files older than X days on Windows 10 from PowerShell Important: It’s recommended to test the command using a temporary folder, as typing the wrong command can cause to deletion of the wrong files. Delete files older than X days automatically from Command Prompt. ![]() Delete files older than X days automatically on Windows 10 using Task Scheduler.Delete files older than X days on Windows 10 from PowerShell.(These steps should also work on Windows 11.) 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. 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. The feature works by deleting junk system files, those files that have been in the recycle bin or Downloads folder for more than a month and making OneDrive content you have used in a while online only.Īlthough 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. On Windows 10, Storage sense is a feature to automatically free up space when you’re running low on storage.
0 Comments
Leave a Reply. |