🧹 Clear Windows Update Cache
Intune Remediation · Purges SoftwareDistribution\Download when it bloats past 1 GB
Test in a pilot group before you point this at the fleet. Detection exits 1 to trigger remediation, 0 to stay put.
Detection Script
D
Detect cache over 1 GB detection
Exits 1 (non-compliant) to trigger remediation. Exits 0 if clean.
›
# Flags a Windows Update download cache over 1 GB.
$path = "$env:WinDir\SoftwareDistribution\Download"
$size = (Get-ChildItem $path -Recurse -File -ErrorAction SilentlyContinue | Measure-Object Length -Sum).Sum / 1GB
if ($size -gt 1) {
Write-Output "Non-compliant: $([math]::Round($size, 2)) GB"
exit 1
}
Write-Output 'Compliant'
exit 0
Remediation Script
R
Stop services, purge, restart remediation
Runs only when detection exits 1.
›
# Stops update services, clears the cache, starts them.
Stop-Service wuauserv, bits -Force
Remove-Item "$env:WinDir\SoftwareDistribution\Download\*" -Recurse -Force -ErrorAction SilentlyContinue
Start-Service bits, wuauserv
Intune Remediation Settings
Run this script using the logged on credentials
No
Enforce script signature check
No
Run script in 64-bit PowerShell host
Yes
Schedule (recommended)
Weekly