Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Declutter Windows 11: Simple Script to Clean Up

· 4 min read · Home Tech

In this article
  1. Write a Basic Cleanup Script
  2. Clear recycle bin
  3. Disable startup items (example: OneDrive)
  4. Run the Script Safely Step by Step
  5. What to Remove vs. What to Keep
  6. Use Windows' Own Cleanup Tools First
  7. Automate the Script with Task Scheduler
  8. When the Script Isn't Enough

Yes, you can declutter Windows 11 with a script. A simple PowerShell script can remove temporary files, clear the recycle bin, and disable startup bloat in one run. For example, the command CleanMgr /sagerun:1 triggers the built-in Disk Cleanup tool automatically.

Write a Basic Cleanup Script

Open Notepad and paste the lines below. Save the file as Declutter.ps1 (the .ps1 extension matters). Then right-click the file and choose "Run with PowerShell". If Windows blocks it, open PowerShell as administrator and run Set-ExecutionPolicy RemoteSigned once.

# Remove temp files
Remove-Item -Path "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinue

Clear recycle bin

Clear-RecycleBin -Force -ErrorAction SilentlyContinue

Disable startup items (example: OneDrive)

Get-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run" | Remove-ItemProperty -Name "OneDrive" -ErrorAction SilentlyContinue

This script does three things: clears your user temp folder, empties the recycle bin, and removes OneDrive from startup. The -ErrorAction SilentlyContinue part stops errors from showing for files that are in use.

Run the Script Safely Step by Step

  1. Press Win + R, type powershell, and press Enter.
  2. Type Set-ExecutionPolicy RemoteSigned and press Enter. Type Y when asked.
  3. Navigate to the folder where you saved the script: cd C:\Users\YourName\Desktop (replace with your path).
  4. Run the script with .\Declutter.ps1.

If you see a red error about execution policy, you skipped step 2. If a file is locked because an app is using it, the script skips it silently—that is normal. Run the script again after closing that app.

What to Remove vs. What to Keep

Most people over-declutter and break something. The temp folder is safe to empty, but do not delete files in C:\Windows\Temp unless you are sure—some are used by system updates. The recycle bin is always safe to empty. Startup items: only remove programs you recognise, like old chat apps or trial software. Never remove anything with "Windows" or "Intel" in the name.

A common mistake is deleting the SoftwareDistribution folder to free space. That folder stores Windows Update files, and deleting it can corrupt future updates. Leave it alone. Instead, use the built-in Storage Sense to remove update leftovers safely.

Use Windows' Own Cleanup Tools First

Before writing a script, try the built-in options. Open Settings > System > Storage. Turn on Storage Sense—it automatically removes temp files and empties the recycle bin every 30 days. Click Cleanup recommendations to see large files and unused apps. This is safer than a script because Windows only deletes what it knows is safe.

For a deeper clean, run Disk Cleanup (search "Disk Cleanup" in the Start menu). Select your drive, click Clean up system files, and check boxes for "Temporary files" and "Delivery Optimization Files". Do not check "Windows Update Cleanup" unless you have not updated in months—it can slow down the next update.

Automate the Script with Task Scheduler

You can run your script weekly without remembering. Open Task Scheduler (search for it). Click Create Basic Task, name it "Weekly Declutter", and choose Weekly as the trigger. Set the day and time, then choose Start a program. In the program field, type powershell.exe. In the arguments field, type -File "C:\path\to\Declutter.ps1" (use your actual path). Finish the wizard.

To test it, right-click the task and choose Run. If nothing happens, check the task's History tab for errors. Most errors come from the script path being wrong or the execution policy blocking it.

When the Script Isn't Enough

If your drive is still full after running the script, look for large files manually. Open File Explorer, go to This PC, and type size:>1GB in the search box. That shows files over 1 GB. Common culprits are old ISO files, video downloads, and the hiberfil.sys file (which stores hibernation data). To disable hibernation, open PowerShell as admin and type powercfg /h off. That frees space equal to your RAM size—for example, 8 GB on a machine with 8 GB RAM.

Another hidden space hog is the WinSxS folder, but you should never delete it manually. Windows manages it automatically. If you need more space, consider moving your Downloads folder to another drive or using an external drive for media.

What if the script deletes something important?

It won't if you stick to the temp folder and recycle bin. The script only touches files in your user temp folder, which Windows itself clears regularly. For extra safety, back up any file you are unsure about before running the script.

Can I undo the startup changes?

Yes. Open Task Manager (Ctrl+Shift+Esc), go to the Startup tab, and re-enable any disabled item. If you removed a registry entry, you can recreate it by opening Registry Editor and adding the value back—but it is easier to just reinstall the app.

Does the script work on Windows 10?

Yes, the same commands work on Windows 10. The only difference is the Settings layout, but the script itself is identical.