PowerShell Commands to Clean Up Windows and Speed It Up Without a Cleaner App 9 min read

PowerShell Commands to Clean Up Windows and Speed It Up Without a Cleaner App

PC optimizer apps promise a faster computer with one click, but most of them simply call tools that Windows already ships with. Many also push paid upgrades after a scan, run background services all day, or, in the worst cases, hide adware. You can skip all of that. A short list of PowerShell commands lets you free up storage, repair broken system files, tune your drives, and fix network glitches, and you stay in control of every change.

PowerShell Commands to Clean Up Windows and Speed It Up Without a Cleaner App

This guide walks through the commands that actually help, explains what each one touches, and points out the "cleanup" commands you should avoid.

PowerShell vs PC Optimizer Apps: Which Cleans Windows Better

Windows already includes every maintenance tool a typical cleaner wraps in a fancy interface.

When you run the commands yourself, you decide what counts as junk. A cleaner app makes that call for you, and some of them wipe caches, logs, or registry keys that Windows actually needs. Running PowerShell directly also shows you real output, so you learn what went wrong instead of staring at a progress bar. Nothing new gets installed, and nothing keeps running after you close the window.

How to Open PowerShell as Administrator

Most of these commands need administrator rights, so open PowerShell the right way first.

  1. Right-click the Start button.
  2. Select Terminal (Admin) or Windows PowerShell (Admin).
  3. Click Yes on the User Account Control prompt.

The Temp folder commands work in a normal window, but DISM, SFC, chkdsk, Optimize-Volume, and the Winsock reset all require the admin window. Create a restore point first if you plan to run the repair commands on a machine you depend on for work.

Method 1: Delete Temp Files in Windows With PowerShell (Safe Preview First)

Your Temp folder collects leftovers from installers and apps, and Windows rarely empties it on its own.

Storage Sense can handle this, but it ships turned off on many PCs and usually acts only when the drive runs low. Instead of deleting blindly, start with a dry run. The following command lists every file in your Temp folder that nobody has modified in the past week, and the -WhatIf switch makes PowerShell report what it would remove without removing anything:

Get-ChildItem "$env:TEMP" -File -Force | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-7) } | Remove-Item -WhatIf

The seven-day filter protects files that running programs still use. To check how much space you stand to gain, replace the last part with a size calculation:

Get-ChildItem "$env:TEMP" -File -Force | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-7) } | Measure-Object -Property Length -Sum

Once the list looks safe, drop the -WhatIf switch to delete the files for real:

Get-ChildItem "$env:TEMP" -File -Force | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-7) } | Remove-Item

Keep two points in mind. This command deletes files permanently, so they never reach the Recycle Bin. It also only touches files sitting directly in the Temp folder and leaves subfolders alone. Never point it at Documents, Downloads, or any folder that holds your personal files.

Method 2: Clean Up the WinSxS Folder With DISM

Windows keeps older copies of updated system components so you can roll back a bad update, and these copies pile up in the WinSxS folder.

A scheduled task eventually removes the old copies, but it waits at least 30 days. You can check the store yourself and trigger the cleanup early. Start with an analysis in an admin window:

DISM /Online /Cleanup-Image /AnalyzeComponentStore

The report shows the true size of the component store, which often sits well below the number File Explorer displays, because Explorer counts hard-linked files twice. Look for the line that says whether Windows recommends a cleanup. If it says Yes, run:

DISM /Online /Cleanup-Image /StartComponentCleanup

If the report says No, close the window and move on. A cleanup at that point frees very little space.

Never delete anything from the WinSxS folder by hand, and skip any third-party tool that promises to shrink it. DISM is the method Microsoft supports.

Method 3: Optimize an SSD or Defrag an HDD With PowerShell

Hard drives and SSDs need different kinds of maintenance, and the Optimize-Volume cmdlet picks the right one for you.

A spinning hard drive benefits from defragmentation, while an SSD needs a TRIM pass that tells the drive which blocks it can clear. Defragmenting an SSD adds wear for no benefit. First, check what kind of drive you have:

Get-PhysicalDisk | Select FriendlyName, MediaType

Next, ask Windows for a health report on the drive without changing anything:

Optimize-Volume -DriveLetter C -Analyze -Verbose

Then run the actual optimization:

Optimize-Volume -DriveLetter C -Verbose
Drive type What Optimize-Volume does What you gain
HDD Defragments the volume Faster file access on a neglected drive
SSD Sends a TRIM (retrim) pass Light housekeeping, small gains

Windows already optimizes drives weekly by default, so save this command for special cases, such as after you move a large batch of files or when you suspect someone turned off the schedule. The -Verbose switch shows each stage as it runs, which the graphical Optimize Drives tool does not.

Method 4: Fix Corrupted Windows System Files With SFC and DISM

Damaged system files cause failed updates, a Settings app that crashes on launch, and programs that quit without warning.

A restart clears memory but leaves broken files in place. DISM and SFC fix the files themselves. Run them in this order from an admin window:

DISM /Online /Cleanup-Image /RestoreHealth
sfc /scannow

DISM repairs the component store first, downloading clean copies from Windows Update, so keep your PC online while it runs. SFC then compares your protected system files against that repaired store and replaces any bad ones.

SFC finishes with one of three results: it found no problems, it found and repaired problems, or it found problems it could not fix. In the last case, run both commands again. These tools fix errors rather than boost raw speed, but a PC stuck in a crash loop usually feels much smoother afterward.

Method 5: Check and Repair Disk Errors With chkdsk

Random freezes, crashes, and vague read errors often trace back to file system problems on the storage drive.

Check Disk scans the drive, repairs file system errors, and recovers data from bad sectors when you add the /r switch:

chkdsk C: /r

Windows cannot scan the system drive while you use it, so chkdsk asks to schedule the scan for the next restart. Type Y, press Enter, and reboot. On a secondary drive, the scan runs right away, though you lose access to that drive until it finishes.

Plan your time. A fast NVMe SSD usually finishes in minutes, while a large, nearly full mechanical drive can take several hours.

Method 6: Fix Internet Problems by Flushing DNS and Resetting Winsock

Connection drops, sites that refuse to load, and apps that go online while others fail often come from stale network settings.

Start with the gentle fixes. These commands request a fresh IP address from your router and clear the DNS cache:

ipconfig /release
ipconfig /renew
ipconfig /flushdns

The release and renew pair may give your PC a new local IP address, so update any router rules tied to the old one. If the problem continues, reset Winsock, the layer that handles network communication in Windows. This undoes damage from faulty VPN clients and malware. Run it in an admin window:

netsh winsock reset

Restart your PC afterward so Windows rebuilds the configuration. To see your full network details at any point, run ipconfig /all.

Method 7: Update All Windows Apps at Once With Winget

Outdated apps cause plenty of bugs and security holes, and updating them one by one wastes time.

Winget, the Windows Package Manager, comes built into Windows 10 and Windows 11. One command checks every supported program and installs available updates:

winget upgrade --all

To see what needs an update before you install anything, run winget upgrade on its own. Winget covers most popular apps, but not all of them, and a few installers still pop up a prompt you need to click through.

Method 8: Empty the Recycle Bin With PowerShell

Deleted files keep using disk space until you empty the Recycle Bin, and on large drives this can add up to many gigabytes.

The following command empties the bin for every drive and skips the confirmation prompt:

Clear-RecycleBin -Force

Check the bin for anything you still need before you run it, because this step cannot be undone.

PowerShell Cleanup Commands to Avoid on Windows

Plenty of scripts online include aggressive commands that cost you safety features in exchange for a little extra space.

  • DISM /ResetBase: This switch removes every superseded component, so you can no longer uninstall any update already on the PC. If a future update breaks something, you lose the easy way back.
  • vssadmin delete shadows: This wipes all System Restore points, which removes your safety net for driver and update problems.
  • Deleting the Prefetch folder: Windows uses Prefetch to launch apps faster. Clearing it makes the next few launches slower, and Windows simply rebuilds it.
  • Registry cleanup scripts: Deleting registry keys in bulk can break installed programs and gives no noticeable speed gain.
  • Clearing event logs: Logs take up little space and hold the clues you need when something goes wrong later.

How Often to Run PowerShell Cleanup Commands

You do not need a weekly routine for most of these commands.

Preview the Temp folder and run the DISM analysis when your free space starts to shrink. Save the DISM and SFC repair pair, chkdsk, and the network resets for times when something actually breaks. Let the built-in weekly schedule handle drive optimization, and run Winget whenever you want to catch up on app updates. If you would rather automate the routine basics, turn on Storage Sense in Settings > System > Storage.

Frequently Asked Questions

Are these PowerShell commands safe to run?

Yes, when you run them as written. The Temp cleanup only touches files older than a week, DISM and SFC use Microsoft's own repair sources, and the network commands only reset settings. Always use the -WhatIf preview before deleting files, and avoid the commands listed in the section above.

Do these commands actually make Windows faster?

Some do, some do not. Clearing space and optimizing a neglected hard drive can improve performance. The repair commands fix errors, which makes a glitchy PC feel smoother, but they do not raise speed on a healthy system.

Why does DISM say a cleanup is not recommended?

DISM only recommends a cleanup when the component store holds enough superseded files to make it worthwhile. If it says no, the scheduled maintenance task already keeps the store in good shape.

Can I run SFC without DISM?

You can, but SFC pulls its replacement files from the component store. If that store is damaged, SFC cannot repair anything. Running DISM first gives SFC healthy copies to work with.

Should I defragment my SSD?

No. SSDs do not benefit from defragmentation. Use Optimize-Volume, which detects the SSD and runs a TRIM pass instead.

Why does chkdsk ask to run on the next restart?

Windows locks the system drive while it runs, so chkdsk cannot scan it in the background. It schedules the scan to run before Windows fully loads on the next boot.

Was this guide helpful?
Fdaytalk

The Fdaytalk editorial team tests games, apps and devices and writes clear, step-by-step fixes and guides.

More from Fdaytalk →

Related reading

More in Tech →