Create a Scheduled PC Cleanup: Temp Files + Recycle Bin Using Task Scheduler (Win10/11)

  • Thread Author

Create a Scheduled PC Cleanup: Temp Files + Recycle Bin Using Task Scheduler (Win10/11)​

Difficulty: Intermediate | Time Required: 20 minutes
A PC that’s used daily quietly accumulates clutter: temporary files, leftover update caches, app temp folders, and a Recycle Bin that never gets emptied “because you might need it later.” Over time, that can waste disk space, slow down searches, and sometimes cause odd app behavior.
This tutorial shows how to create a safe, repeatable scheduled cleanup using Task Scheduler on Windows 10 and Windows 11, focusing on two low-risk targets:
  • Temp files (current user and system temp)
  • Recycle Bin (all drives)
You’ll create a PowerShell cleanup script, test it manually, then schedule it to run automatically (weekly or monthly).

Prerequisites​

  • Windows 10 or Windows 11 (any edition with Task Scheduler)
  • An account with Administrator access (recommended for system temp cleanup)
  • PowerShell 5+ (built-in on Windows 10/11)
  • A few minutes where the PC can run the cleanup (ideally when idle)
Note: This guide avoids aggressive cleaning (like deleting browser profiles, Downloads, or unknown “cache” folders). The goal is a reliable baseline cleanup you can schedule without anxiety.

Step-by-step: Create the cleanup script​

1) Create a folder to store your script​

  1. Open File Explorer
  2. Go to: C:\Scripts
    • If it doesn’t exist, create it.
  3. Inside C:\Scripts, create a file named:
    ScheduledCleanup.ps1
Tip: Keeping scripts in a dedicated folder makes scheduling and troubleshooting much easier.

2) Paste in a safe cleanup script​

  1. Right-click ScheduledCleanup.ps1Edit (or Edit in Notepad)
  2. Paste the following script:
Code:
# ScheduledCleanup.ps1
# Cleans temp folders + empties Recycle Bin (Windows 10/11)

$ErrorActionPreference = "SilentlyContinue"

Write-Output "=== Scheduled Cleanup started: $(Get-Date) ==="

# Temp locations
$tempPaths = @(
    "$env:TEMP\*",
    "$env:WINDIR\Temp\*"
)

foreach ($path in $tempPaths) {
    Write-Output "Cleaning: $path"
    Remove-Item -Path $path -Recurse -Force -ErrorAction SilentlyContinue
}

# Empty Recycle Bin (all drives)
Write-Output "Emptying Recycle Bin..."
Clear-RecycleBin -Force -ErrorAction SilentlyContinue

Write-Output "=== Scheduled Cleanup finished: $(Get-Date) ==="
  1. Save the file.
Warning: This script deletes files from Temp folders without prompting. That’s usually safe, but open apps may temporarily store working files there. Schedule it at a time you’re unlikely to be actively working (for example, early morning).

Step-by-step: Test the script manually (important!)​

3) Run PowerShell as Administrator​

  1. Press Start
  2. Type PowerShell
  3. Right-click Windows PowerShellRun as administrator

4) Allow script execution (one-time setup)​

Windows often blocks scripts by default. We’ll allow scripts only for the current user (a common, safer choice):
Run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
If prompted, type Y and press Enter.
Note: RemoteSigned allows locally created scripts to run, but requires downloaded scripts to be signed. That’s a reasonable balance for most home and power users.

5) Run the script​

In the same PowerShell window:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\ScheduledCleanup.ps1"
If it completes without errors, you’re ready to schedule it.
Tip: If you want to see output later, we’ll add logging when creating the scheduled task.

Step-by-step: Create the scheduled task in Task Scheduler​

6) Open Task Scheduler​

  1. Press Win + R
  2. Type: taskschd.msc
  3. Press Enter

7) Create a new task (not “Basic Task”)​

Using Create Task gives better control.
  1. In the right pane, click Create Task…

General tab​

  1. Name: Scheduled PC Cleanup (Temp + Recycle Bin)
  2. Description: Deletes temp files and empties Recycle Bin on a schedule.
  3. Select Run whether user is logged on or not
  4. Check Run with highest privileges
  5. Configure for:
    • Windows 10 if you’re on Win10
    • Windows 11 tasks typically still use “Windows 10” here—either works fine on Win11.
Note (Win11): The “Configure for” dropdown may still list Windows 10. That’s normal; Task Scheduler’s compatibility labels aren’t always updated.

8) Add a trigger (when it runs)​

Go to the Triggers tab:
  1. Click New…
  2. Begin the task: On a schedule
  3. Choose one:
    • Weekly (recommended): pick a day/time
    • Monthly (if you rarely need cleaning)
  4. Check Enabled
  5. Click OK
Tip: A weekly schedule (e.g., Sunday at 3:00 AM) is a good starting point. If you’re on a laptop that’s often asleep, schedule it for a time you know it’s typically on.

9) Add the action (run PowerShell + logging)​

Go to the Actions tab:
  1. Click New…
  2. Action: Start a program
  3. Program/script:
    powershell.exe
  4. Add arguments (important):
    -NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\ScheduledCleanup.ps1" *> "C:\Scripts\ScheduledCleanup.log"
  5. Start in (optional but recommended):
    C:\Scripts
  6. Click OK
Note: The *> redirects all output (including errors) into a log file you can check later.

10) Configure conditions (optional but recommended)​

Go to the Conditions tab:
Suggested settings:
  • If this is a desktop:
    • You can leave defaults, or check Start the task only if the computer is idle for: 10 minutes.
  • If this is a laptop:
    • Consider checking Start the task only if the computer is on AC power to avoid running during battery use.
Tip: If you often close your laptop lid (sleep), your task may not run at the scheduled time. That’s normal—see troubleshooting for “missed runs.”

11) Configure additional reliability settings​

Go to the Settings tab:
Recommended:
  • Check Allow task to be run on demand
  • Check Run task as soon as possible after a scheduled start is missed
  • Optional: Check Stop the task if it runs longer than: 1 hour (it shouldn’t, but it’s a safety net)
Click OK.
When prompted, enter your Windows account password to save the task.

Step-by-step: Test the scheduled task​

12) Run it on demand​

  1. In Task Scheduler, find your task (Task Scheduler Library)
  2. Right-click it → Run
  3. Wait 10–30 seconds
  4. Check the log file:
    • C:\Scripts\ScheduledCleanup.log
Also verify:
  • Recycle Bin is emptied
  • Temp space has been reduced (optional check in Settings → System → Storage)

Tips and troubleshooting​

Task runs, but nothing seems to happen​

  • Check C:\Scripts\ScheduledCleanup.log
  • Some temp files can’t be deleted because they’re in use. That’s expected.

“Clear-RecycleBin is not recognized”​

This cmdlet is standard in Windows PowerShell 5+ on Windows 10/11. If it fails:
  • Make sure the task runs with powershell.exe (Windows PowerShell), not PowerShell 7 (pwsh.exe) unless you know your environment.
  • Confirm PowerShell version by running:
    $PSVersionTable.PSVersion

The task didn’t run at the scheduled time​

  • If the PC was asleep/off, it won’t run unless you:
    • Enable Run task as soon as possible after a scheduled start is missed (we did)
    • Optionally enable Wake the computer to run this task (Conditions tab)

Want to be extra cautious?​

  • Change the trigger to run when idle
  • Schedule it weekly at a time you’re unlikely to be working
  • Keep the log file so you can confirm behavior
Warning: Avoid adding “Downloads”, random AppData folders, or registry cleaners to this task. Scheduled over-cleaning is a common cause of “mysterious” app issues.

Conclusion​

With a simple PowerShell script and Task Scheduler, you can automate a dependable cleanup routine that removes temporary clutter and keeps your Recycle Bin from growing indefinitely. It’s a practical “set it and forget it” maintenance task that can reclaim disk space and reduce minor system sluggishness—without relying on third-party cleaners.
Key Takeaways:
  • Automate safe cleanup of Temp folders and Recycle Bin using built-in Windows tools
  • Use Task Scheduler + highest privileges for reliable results
  • Add logging to quickly diagnose issues and confirm the task ran
  • Configure triggers/conditions to match how your PC is actually used (sleep, battery, idle)

This tutorial was generated to help WindowsForum.com users get the most out of their Windows experience.
 

Back
Top