Overview
This Intune Proactive Remediation package automatically identifies and removes unnecessary files consuming disk space on Windows endpoints. It follows the standard Detect → Remediate pattern used by Microsoft Intune.
What It Cleans
- Windows Temp —
%WINDIR%\Temp - Windows Update Cache —
%WINDIR%\SoftwareDistribution\Download - User Temp Folders —
C:\Users\*\AppData\Local\Temp(excludes system/default profiles) - Recycle Bin —
$Recycle.Binon all local fixed drives
How It Works
Detection Script
The detection script scans all target paths and calculates the total cleanable size. If the total exceeds the 1 GB threshold, it returns exit code 1 (remediation required). Otherwise, it returns 0 (compliant).
$ThresholdBytes variable in the detection script. Default is 1GB. Increase it for servers or decrease it for thin clients.Remediation Script
When triggered, the remediation script removes all files from the targeted folders. It gracefully handles locked files and access-denied errors — files in use are simply skipped without causing failures.
After cleanup, the script reports the total freed space and remaining cleanable space in the Intune console output.
Deployment in Intune
- Go to Devices → Remediations in the Intune admin center
- Create a new remediation script package
- Upload the Detection script and Remediation script
- Set Run this script using the logged-on credentials: No
- Set Run script in 64-bit PowerShell: Yes
- Assign to a device group and set a schedule (daily or weekly recommended)
REMEDIATE: completed | freed=2.45 GB | remaining=0.12 GBExcluded Profiles
The following user profiles are excluded from temp folder cleanup to avoid interfering with system accounts:
- All Users, Default, Default User, Public
- defaultuser0, WDAGUtilityAccount, Administrator
Output Format
Both scripts produce structured one-line output for easy parsing in Intune reports:
- Detection:
DETECT: remediation required | cleanable=2.45 GB | threshold=1 GB - Remediation:
REMEDIATE: completed | freed=2.45 GB | remaining=0.12 GB