Skip to content
Menu

Disk Full First Aid - Silent Cleanup

Clears temp files, the Windows Update download cache, crash dumps and error reports on the system drive, and says how much it freed. User documents and the Recycle Bin stay.

Disk Full First Aid: Silent Cleanup is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Disk Full First Aid: Silent Cleanup. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, Windows 11, Windows Server 2016+; runs as SYSTEM
NeedsPowerShell 5.1, administrator rights
Changes thingsChanges what it runs on

What It Does

The script looks at the places that fill a system drive without anyone noticing: the Windows Temp folder and every user's Temp folder, the Windows Update download cache, the Delivery Optimization cache, crash dumps, and Windows Error Reporting queues. It measures each one first and requires at least MinimumMB of estimated savings unless ComponentCleanup is on.

File cleanup skips files changed within MinAgeDays and counts locked files it cannot delete. Delivery Optimization and DISM cleanup have no age cutoff. To clear the update download cache it stops the Windows Update service and puts it back the way it found it. Browser caches for Chrome, Edge and Firefox (never cookies, passwords or history) and DISM component cleanup only run when you turn them on.

It never empties the Recycle Bin, and it never touches documents, desktops, downloads, application settings or installed programs. The table has one row per category, and the answer says how much was freed and how full the drive was before and after.

Before You Run It

  • Run it with DryRun=true first on one machine and read what it would delete.
  • Leave IncludeBrowserCaches off unless the client agrees. Pages load more slowly for a day while the caches refill.
  • Turn on ComponentCleanup only in a maintenance window. It can take many minutes and its size is only known afterwards.
  • If the drive fills again within a week, the cause is something this script does not clear. Look for it before you schedule the cleanup.

Type and Risk

  • Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
  • Risk: Low. Set DryRun=true, or run it with -WhatIf, to list every change without making any.
  • What it changes: Deletes temp, update-cache, crash-dump and error-report files; optionally browser caches and DISM component leftovers; briefly stops and restarts Windows Update.
  • Restart: It never restarts the machine.
  • Typical run: 1 to 10 minutes (longer with ComponentCleanup).
  • Example answer: "Freed 6.2 GB on C: (was 4% free, now 9%)"
  • Tested before listing on Windows 11 with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • MinAgeDays: Only delete files that have not been modified for at least this many days, so files a program is using right now survive. Whole number, 0 to 3650. Default 2.
  • MinimumMB: Do nothing unless at least this many MB can be freed. Whole number, 0 to 1048576. Default 50.
  • IncludeBrowserCaches: true to also clear the Chrome, Edge and Firefox cache folders of every profile. Default false.
  • ComponentCleanup: true to also run DISM component store cleanup (can take many minutes). Default false.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

clear-disk-space.ps1 · 1045 lines · 52.5 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.