Skip to content

Aaryan0118/PowerShell-Temp-Cleaner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Temp Cleaner

A PowerShell utility that safely cleans temporary files from common Windows locations, reports what it did, and keeps a timestamped log of every run.

Features

  • 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
  • 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 -Version flag

Requirements

  • 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.

Installation

  1. Download TempCleaner.ps1.

  2. Place it in a folder you control (e.g. Desktop\TempCleaner).

  3. If needed, allow local scripts to run for your current session:

    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Usage

Run interactively (asks for confirmation):

.\TempCleaner.ps1

Run unattended, no prompt:

.\TempCleaner.ps1 -Auto

Run with per-item detail:

.\TempCleaner.ps1 -Auto -VerboseOutput

Clean everything, including the optional extras:

.\TempCleaner.ps1 -Auto -IncludePrefetch -IncludeRecent -IncludeWindowsUpdateCache -IncludeRecycleBin

Show version info only:

.\TempCleaner.ps1 -Version

Show full help:

Get-Help .\TempCleaner.ps1 -Full

All Parameters

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

Example Output

==========================================
          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.

Notes and Caveats

  • 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: SizeFreed is 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.

Future Plans

  • Scheduled Task installer helper
  • CSV/JSON export of results in addition to the text log
  • A -WhatIf dry-run mode

License

MIT — see LICENSE.

About

A professional PowerShell utility to safely clean Windows temporary files with detailed reporting, logging, and administrator support.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors