Library / Windows endpoint

WIN-001 · Script

Disk Space Monitor and Cleanup

Checks free space on the system drive and optionally removes safe-to-delete temporary data.

Version 1.0.0Language PowerShellUpdated November 2026

What it does

Report mode (default) measures free space and reports how much space common temporary locations are using. Clean mode removes only data Windows recreates on its own: system temp, user temp files older than a set age, the Windows Update download cache, Delivery Optimization cache, and the Recycle Bin. It never touches Documents, Desktop, Downloads, or any user data folders.

Requirements

Windows PowerShell 5.1+, run as SYSTEM or local admin

How to run it

  • Run as: SYSTEM or a local administrator
  • Run from: any RMM or MDM, Intune, a Group Policy startup script, a scheduled task, or an elevated PowerShell window
  • Script type: PowerShell, 64-bit
  • User interaction: none; the script never prompts
  • Timeout: 10 minutes (30 for Windows Update installs)

Settings

NameWhat it doesOptionsDefault
ModeReport (default) or Clean.Report, CleanReport
MinFreePercentAlert if free space on the system drive is below this percent. Default 15.15
TempAgeDaysOnly delete temp files older than this many days. Default 7.7

Exit codes

  • 0 = free space OK, 1 = below threshold, 2 = script error

Testing steps

  1. Run it first with the mode set to Report on one test device. Nothing is changed in that mode.
  2. Read the log and confirm the planned changes are what you expect.
  3. Run your chosen settings on the same test target and confirm the result.
  4. Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
  5. Roll out to a small group next, then everyone.

Rollback steps

Report mode changes nothing. Clean mode deletes only temporary files and empties the Recycle Bin; those files are not meant to be kept, so there is nothing to restore.

Version and change log

VersionDateChanges
1.0.0November 2026First release.