Simple scripts to clear temp files, browser cache/history, caches for applications like Microsoft Teams, Slack, Discord, Opera, and OneDrive, and remove Windows Defender scan and definition update backups (including the NisBackup folder), Windows dump files, and Windows Error Reporting (WER) temp files
To run this with parameters, do the following:
- Download the .zip file on the main page of the GitHub and extract the .zip file to your desired location, e.g. -
c:\WindowsClearCache
- Once extracted, open PowerShell (or PowerShell ISE) as an Administrator
- Enable PowerShell execution:
Set-ExecutionPolicy Unrestricted -Force
(to allow executing unsigned code) - Run the Disk Cleanup utility (cleanmgr.exe) with the /sageset:1 option, which allows users to configure cleanup settings before executing the actual cleanup process
e.g. -
cleanmgr.exe /sageset:1
- On the prompt, change to the directory where you extracted the files:
e.g. -
cd c:\Program Files\WindowsClearCache
- Next, to run the script, enter in the following:
e.g. -
.\DriveClean.ps1
Optional flags:
- Use
-DryRun
to preview the files that would be deleted without removing them. - Use
-Verbose
to display each file as it is deleted (or would be deleted in dry run).
Verified on the following platforms:
Windows Version | Yes/No? |
---|---|
Windows Server 2025 | ??? |
Windows Server 2022 | Yes |
Windows Server 2019 | Yes |
Windows Server 2016 | Yes |
Windows Server 2012 R2 | Yes |
Windows Server 2012 | Yes |
Windows Server 2008 R2 | Yes |
Windows Server 2008 | Yes |
Windows Server 2003 | No |
Windows 11 | Yes |
Windows 10 | Yes |
Windows 8 | ??? |
Windows 7 | ??? |
Windows Vista | No |
Windows XP | No |
Windows 2000 | No |
It is likely to work on other platforms as well. If you try it and find that it works on another platform, please let me know.
WARNING: I do NOT take responsibility for what may happen to your system! Run scripts at your own risk!