Windows and applications create temporary files constantly: installers unpack into temp folders, browsers cache pages, Windows Update keeps downloaded packages. Most are cleaned automatically, but on systems that run for months — especially servers with small disks — they can grow to many gigabytes.
Where temporary data lives
| Location | Contents | Safe to clean? |
|---|---|---|
%TEMP% (C:\Users\<you>\AppData\Local\Temp) |
Per-user temp files | Yes (files in use are skipped) |
C:\Windows\Temp |
System and service temp files | Yes, older files |
C:\Windows\SoftwareDistribution\Download |
Windows Update downloads | Yes, with the update service stopped |
C:\Windows\WinSxS |
Component store (updates, features) | Only via DISM, never by hand |
C:\Windows\Prefetch |
App launch optimization data | Not recommended — it’s small and rebuilds |
| Browser caches | Cached web content | Yes, via the browser |
C:\$Recycle.Bin |
Deleted files | Yes, by emptying the Recycle Bin |
C:\Windows\Installer |
MSI files needed for repair/uninstall | No — deleting breaks updates and uninstalls |
C:\Windows.old |
Previous Windows version after an upgrade | Yes, once you’re sure you won’t roll back |
Method 1: Storage Sense (Windows 10/11)
Settings → System → Storage → Storage Sense — turn it on and set it to delete temporary files, empty the Recycle Bin and clear Downloads after a number of days. Cleanup recommendations on the same page shows large and unused files.
Method 2: Disk Cleanup (all versions, including Server)
Run cleanmgr, choose the drive, then Clean up system files for more options: Windows Update Cleanup, Delivery Optimization files, previous installations, temporary files.
On Windows Server, Disk Cleanup is available on recent versions; on older ones it requires the Desktop Experience feature.
Method 3: PowerShell
Delete temp files older than 7 days:
$paths = "$env:TEMP", "C:\Windows\Temp"
foreach ($p in $paths) {
Get-ChildItem $p -Recurse -Force -ErrorAction SilentlyContinue |
Where-Object { -not $_.PSIsContainer -and $_.LastWriteTime -lt (Get-Date).AddDays(-7) } |
Remove-Item -Force -ErrorAction SilentlyContinue
}
Clear the Windows Update download cache:
Stop-Service wuauserv, bits
Remove-Item C:\Windows\SoftwareDistribution\Download\* -Recurse -Force
Start-Service wuauserv, bits
Shrink the component store safely:
Dism.exe /Online /Cleanup-Image /StartComponentCleanup
# /ResetBase removes the ability to uninstall existing updates — use with care
Find what’s really using space
Temp files are often not the biggest problem. Check:
Get-ChildItem C:\ -Directory -Force -ErrorAction SilentlyContinue |
ForEach-Object { [pscustomobject]@{ Folder = $_.FullName;
GB = [math]::Round((Get-ChildItem $_.FullName -Recurse -Force -File -ErrorAction SilentlyContinue |
Measure-Object Length -Sum).Sum / 1GB, 2) } } |
Sort-Object GB -Descending | Select-Object -First 10
Common surprises: application logs (IIS logs in C:\inetpub\logs), database files, old backups, trading terminal history, the page file and hibernation file (powercfg /h off removes hiberfil.sys on servers that never hibernate).
Automate on a server
Save the PowerShell cleanup as C:\Scripts\cleanup.ps1 and schedule it weekly with Task Scheduler. Add IIS log rotation:
Get-ChildItem C:\inetpub\logs\LogFiles -Recurse -Filter *.log |
Where-Object LastWriteTime -lt (Get-Date).AddDays(-30) | Remove-Item
Don’t
- Delete
WinSxSorInstallercontents by hand. - Use “registry cleaners” — they don’t free meaningful space and can break things.
- Delete files from
Program FilesorProgramDatawithout knowing what they are.
Related: Windows disk partition management if you need more space on the system drive, and Windows Search indexing. Windows Server needs at least 50 GB of disk; our Windows VPS plans start above that.