A PowerShell utility that safely cleans temporary files from common Windows locations, reports what it did, and keeps a timestamped log of every run.
- Cleans Windows Temp (
C:\Windows\Temp) and User Temp (%TEMP%) by default - Optional additional locations, off by default:
- Prefetch (
C:\Windows\Prefetch) - Recent Items (
%APPDATA%\Microsoft\Windows\Recent) - Windows Update Cache (
C:\Windows\SoftwareDistribution\Download) - Recycle Bin
- Prefetch (
- Deletes hidden/system items (
-Force), and cleans up empty folders left behind - A locked file no longer blocks the rest of a folder — each item is deleted individually
- Reports per-location and overall: items found, deleted, remaining, cleanup %, files vs. folders deleted, total size freed, and errors broken down by exception type
- Live progress bars (overall + per-folder) via
Write-Progress - Optional verbose mode for a per-item deleted/skipped trace
- Command-line switches for unattended/scheduled runs (
-Auto) - A new timestamped log file every run — nothing gets overwritten
- Comment-based help (
Get-Help/-?support) and a-Versionflag
- Windows PowerShell 5.1 or PowerShell 7+
- Administrator privileges are required to clean Windows Temp, Prefetch, and the Windows Update Cache. Without admin rights, those locations are skipped and reported as such — the script still runs fine for User Temp and Recent Items.
-
Download
TempCleaner.ps1. -
Place it in a folder you control (e.g.
Desktop\TempCleaner). -
If needed, allow local scripts to run for your current session:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Run interactively (asks for confirmation):
.\TempCleaner.ps1Run unattended, no prompt:
.\TempCleaner.ps1 -AutoRun with per-item detail:
.\TempCleaner.ps1 -Auto -VerboseOutputClean everything, including the optional extras:
.\TempCleaner.ps1 -Auto -IncludePrefetch -IncludeRecent -IncludeWindowsUpdateCache -IncludeRecycleBinShow version info only:
.\TempCleaner.ps1 -VersionShow full help:
Get-Help .\TempCleaner.ps1 -Full| Parameter | Description |
|---|---|
-VerboseOutput |
Show a per-item Deleted/Skipped line during cleanup |
-Auto |
Skip the Y/N confirmation prompt |
-SkipPrompt |
Same as -Auto |
-IncludePrefetch |
Also clean C:\Windows\Prefetch (admin required) |
-IncludeRecent |
Also clean Recent Items |
-IncludeWindowsUpdateCache |
Also clean the Windows Update download cache (admin required) |
-IncludeRecycleBin |
Also empty the Recycle Bin (destructive) |
-Version |
Print version info and exit |
==========================================
TEMP CLEANER v2.0
==========================================
Date : 10-Jul-2026
Time : 09:15:32 AM
Administrator : YES
==========================================
WINDOWS TEMP
==========================================
Folder Status : Found
Path : C:\Windows\Temp
Items Found : 42
Deleted : 40
Remaining : 2
Status : Some files are currently in use.
==========================================
SUMMARY
==========================================
Windows Temp
Found : 42
Deleted : 40
Remaining : 2
Cleaned : 95%
User Temp
Found : 118
Deleted : 118
Remaining : 0
Cleaned : 100%
Overall
Files Deleted : 150
Folders Deleted : 8
Total Size Freed : 214.37 MB
Total Found : 160
Total Deleted : 158
Total Remaining : 2
Cleanup Percent : 99%
Overall Status : COMPLETED WITH WARNINGS
==========================================
Cleanup Completed Successfully!
Execution Time : 3.42 Seconds
Log File Saved :
Path : C:\Users\YourName\Desktop\TempCleaner\cleanup-2026-07-10-09-15.txt
==========================================
See sample-log/cleanup-sample.txt for a full example log file.
- Windows Update Cache: for the cleanest removal, consider stopping the Windows
Update service (
wuauserv) before running with-IncludeWindowsUpdateCache, otherwise some files may be locked and reported as remaining. - Recycle Bin:
SizeFreedis not tracked for this step — Windows' Recycle Bin COM interface doesn't expose per-item size in a reliable way, so it's reported as part of the item counts only, not the size total. - The optional locations are off by default on purpose. Turn them on explicitly with the switches above.
- Scheduled Task installer helper
- CSV/JSON export of results in addition to the text log
- A
-WhatIfdry-run mode
MIT — see LICENSE.