Stops the Windows Update service, removes the SoftwareDistribution folder and starts the service again, which is the standard fix for updates that fail to download or install with no useful error. The script refuses to run without administrator rights instead of failing halfway through.
powershell
# Clear the Windows Update cache
#-------------------------------------------------
$isadm = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isadm) {
Write-Host "<WRITE-LOG = ""*Please run this script as Administrator.*"">"
Show-Warning "Please run this script as Administrator."
Write-Host "<WRITE-LOG = ""*If this was a remote execution please provide Administrator credentials.*"">"
Write-Error "Warning: Not running as Administrator."
} else {
Stop-Service wuauserv -Force
Remove-Item -Path "C:\Windows\SoftwareDistribution" -Recurse -Force
Start-Service wuauserv
Write-Host "Windows Update cache cleared!"
}Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in Self-Healing & Repair
Automate Disk Cleanup with PowerShell
2026-08-17Remove Windows Bloatware Apps with PowerShell
2026-08-17Flush the DNS Cache with PowerShell
2026-08-17Clear a Stuck Print Queue with PowerShell
2026-08-17Delete Old Temp Files with PowerShell
2026-08-17Repair Windows System Files with DISM and SFC
2026-08-17Ready when you are.
Try ServerEngine free for 7 days.