Computer >> Computer tutorials >  >> Troubleshooting >> computer maintenance

Save Hours on Windows Maintenance with 4 PowerShell One-Liners

Save Hours on Windows Maintenance with 4 PowerShell One-Liners

Published Mar 27, 2026, 6:00 AM EDT

Afam's experience in tech publishing dates back to 2018, when he worked for Make Tech Easier. Over the years, he has built a reputation for publishing high-quality guides, reviews, tips, and explainer articles, covering Windows, Linux, and open source tools. His work has been featured on top websites, including Technical Ustad, Windows Report, Guiding Tech, Alphr, and Next of Windows.

He holds a first degree in Computer Science and is a strong advocate for data privacy and security, with several tips, videos, and tutorials on the subject published on the Fuzo Tech YouTube channel.

When he is not working, he loves to spend time with his family, cycling, or tending to his garden. 

Most people may resort to PowerShell commands when they encounter common Windows problems. However, some PowerShell maintenance commands can help avoid some of these problems. While a lot of them may be complex, some are one-liners that you can easily remember and keep handy. These one-liners make maintenance less burdensome. They have become indispensable tools in my maintenance arsenal.

Update every app on your PC in one shot

Stop hunting for update buttons across every program

Save Hours on Windows Maintenance with 4 PowerShell One-Liners

Some of the major crashes you experience on Windows are triggered by outdated apps. They can also trigger system lag, and because they may leave certain vulnerabilities unpatched, they become a security concern that can allow malicious actors to install malware or steal data.

Winget is a built-in Windows package manager that I can run in PowerShell. It gives me access to a one-line command that allows me to update almost every app on my computer at once. Here is the command that I run:

winget upgrade --all --include-unknown

If Winget is missing, you can install it via the App Installer package in the Microsoft Store.

This command includes two important flags:

  • --all updates all apps in one go
  • --include-unknown captures apps whose installed version can't be detected, like browsers or dev tools

When you run this command, you should get a list of updated apps, skipped apps, and version numbers. I like the feedback because it helps me know what apps may require manual attention. It's one of the most practical ways to update Windows apps, and it reduces the dependence on individual app checks.

Certain apps require admin rights for updates, so you should run the upgrade command in an elevated PowerShell for the best results.

Clear out temp junk before it quietly slows you down

Run this monthly and stop thinking about disk bloat

Save Hours on Windows Maintenance with 4 PowerShell One-Liners

With regular computer use, you risk running out of storage on your device. This is because, as temp files accumulate, they can quietly fill gigabytes of space. They are products of installation leftovers, browser caches, and app temp files.

As they pile up, you may notice your computer's performance is slower, and in some cases, they can trigger minor app glitches. Windows has built-in options for cleaning temp files, and you may even do it manually. But PowerShell has a one-liner command that is fast and efficient for clearing temp files:

Get-ChildItem $env:TEMP -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue

The scope of this command is limited to $env:TEMP. Temp files are also gathered in C:\Windows\Temp and may need to be cleared separately.

The command includes the -ErrorAction SilentlyContinue flag, which ensures all files currently in use are skipped. This flag ensures the command is completed safely and uninterrupted.

Once the command completes, you will instantly reclaim disk space, and the amount typically ranges from hundreds of megabytes to multiple gigabytes.

To get the best results, do not run it when critical apps are running, as they may lock certain temporary files.

This one-line command works better than a manual cleanup because you don't have to open multiple tools, navigate through several menus, or guess which files can be safely deleted.

Repair Windows before a small glitch becomes a big problem

Run SFC and DISM together for the deepest fix

I've observed over the years that a healthy Windows installation can still accumulate minor corruption in system files or the component store. If this happens for an extended period, it results in freezes, app crashes, or slow startups. If you do maintenance early, you will avoid this inconvenience.

Here's the command I use:

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

This command has two parts, and the order is important:

  • DISM repairs the Windows Component Store (WinSxS).
  • SFC replaces corrupted system files with healthy cached versions drawn from the repaired Component Store.

The two commands will run sequentially and may take several minutes. After they are complete, a reboot is essential for the repairs to take full effect. While it's not required, I sometimes pair this command with the PSWindowsUpdate module when I need to automate operating system updates with system repair.

It's a more convenient option compared to manually troubleshooting freezes and crashes, which may take hours.

Find what’s actually eating your storage

Surface the files Windows Explorer is hiding from you

Save Hours on Windows Maintenance with 4 PowerShell One-Liners

You do not always have a clear reason when Windows fills your drives, and even when you check storage in File Explorer, you may only be scratching the surface. It's not always straightforward to find the hidden log files, old installers, and forgotten downloads. But with this PowerShell command, you can figure out the real culprits:

Get-ChildItem -Path C:\Users -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.Length -gt 500MB } | Sort-Object Length -Descending | Select-Object FullName, @{Name="Size(GB)";Expression={[math]::Round($_.Length/1GB,2)}}

The command's scope is limited to C:\Users, where a majority of the large files are likely to be, but you may expand it to C: if needed.

Including Size(GB) in the command ensures raw byte counts are formatted as clear, actionable numbers. The command sorts results by size, highlighting the largest files. If you do not use this command, you may have to keep guessing what's filling your disk.

This is the 10-minute routine I actually stick to

These four commands are my monthly maintenance pass. They handle app updating, junk cleaning, storage hog identification, and system file repairs. There are other maintenance commands you can run regularly, but these four are a good starting point. They are practical, proactive, and efficient for real-world maintenance.

Save Hours on Windows Maintenance with 4 PowerShell One-Liners Related