-
Notifications
You must be signed in to change notification settings - Fork 5
disk_cleanup.ps1
Corey Watson edited this page Dec 1, 2025
·
1 revision
Windows disk cleanup automation with targeted cleanups.
Runs Windows Disk Cleanup utility on all fixed local drives, plus targeted cleanups for SoftwareDistribution, WinSxS, and Search Index to free up disk space.
Automates comprehensive disk cleanup for managed Windows endpoints, including system-level caches and component stores that require elevated privileges.
- Windows 10/11 with cleanmgr.exe and DISM
- WMI service running
- Administrator privileges for DISM/services
- CleanupProfile: Cleanup aggressiveness level (default: 'verylow')
- DriveType filter: 3 (fixed local disks only)
- Cleanups run sequentially to avoid conflicts
- DISM targets system-wide (C: only)
- Checks/elevates to admin
- Queries WMI for fixed drives
- Runs cleanmgr.exe per drive with /verylowdisk flag
- Performs targeted cleanups on C: (SoftwareDistribution, WinSxS, Search Index)
- Reports progress/completion
- No secrets in logs
- Targeted deletions only (no user files)
- 0: Success
- 1: Failure (validation/WMI/admin check)
[ INPUT VALIDATION ]
--------------------------------------------------------------
Cleanup Profile : verylow
Running as Admin : True
[ OPERATION ]
--------------------------------------------------------------
Querying fixed local drives...
Found 2 drive(s) : C:, D:
Running cleanup for drive C: (cleanmgr)
Running cleanup for drive D: (cleanmgr)
Running SoftwareDistribution cleanup...
Running WinSxS cleanup via DISM...
Rebuilding Search Index...
[ RESULT ]
--------------------------------------------------------------
Status : Success
Drives Processed : 2
Targeted Cleanups : 3/3
[ FINAL STATUS ]
--------------------------------------------------------------
Disk cleanup completed successfully. Reboot recommended for full effect.
[ SCRIPT COMPLETED ]
--------------------------------------------------------------
- v1.1.0 (2025-11-29): Added SoftwareDistribution, DISM WinSxS, Search Index; admin check
- v1.0.0 (2025-10-28): Initial implementation
- View Script Source
- Scripts - Back to script index