I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself

Task Scheduler is one of the most underused tools in Windows 11. These five scripts turn it into the maintenance assistant your PC has needed all along.

I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself
Comment IconFacebook IconX IconReddit Icon
Guides Editor
Published
6 minutes & 30 seconds read time
Voice: Yasir Mahmood
0:00 / 10:08
Use left and right arrow keys to seek audio.

Windows maintenance is the kind of thing you know you should do and almost never actually do. Clearing temp files, flushing DNS, and running Disk Cleanup each take a few minutes, but those minutes add up over the year. Task Scheduler, built into Windows 11, lets you offload all of it. I have five tasks running in the background, and I don't touch any of them.

Clearing temp files weekly keeps Windows from drowning in its own junk

Windows and the apps you install dump temporary files into %TEMP% and C:\Windows\Temp constantly. Most never come back to clean up, so these folders quietly balloon with installer leftovers, browser cache fragments, and crash dumps that nobody's touched in months. A fresh PC won't show the damage, but a PC that's been running for a year definitely will.

Task Scheduler is a built-in Windows utility that runs programs, scripts, and commands at set times or in response to specific events such as logins, idle periods, system startup, or whatever you define. It's been part of Windows for decades and handles the kind of recurring work you'd otherwise have to remember yourself. To open it, press Win + R, type taskschd.msc, and hit Enter. You can also search "Task Scheduler" from the Start menu.

I use the following short PowerShell script that deletes anything older than seven days from both folders, skipping files currently in use, so nothing active gets yanked:

Get-ChildItem -Path "$env:TEMP","C:\Windows\Temp" -Recurse -Force -ErrorAction SilentlyContinue | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-7) } | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue

Populate the above script in a new text document and save it as cleanup-temp.ps1 somewhere you won't accidentally delete it. I keep mine in C:\Scripts\.

Photo of the Samsung 9100 PRO 1TB SSD

Best Deals: Samsung 9100 PRO 1TB SSD

Prices last scanned 9 hours and 6 minutes ago

* Prices may be inaccurate. As an Amazon Associate, we earn from qualifying purchases. We earn affiliate commission from any Newegg or PCCG sales.

I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 01

Now, open Task Scheduler and hit Create Basic Task. Name it, set a weekly trigger for Sunday at 3 AM (or whenever your PC is usually on), and choose Start a program for the action. Then point it to powershell.exe and paste -ExecutionPolicy Bypass -File "C:\Scripts\cleanup-temp.ps1" into the arguments field.

I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 02
I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 03
I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 04
I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 05

Before saving, tick Run with highest privileges in the General tab. Without it, the task can't touch C:\Windows\Temp and skips half the job - the single most common reason scheduled tasks seem to do nothing.

I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 06
I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 07

I usually keep the seven-day cutoff. Some installers write to %TEMP% and expect files to remain in place for a session, so dropping it to 1 day can break installs that are still in progress.

Flushing the DNS cache every Sunday fixes weird browsing issues before they start

Windows keeps a local record of every domain you've visited recently, so it doesn't have to ask your DNS server each time. That cache speeds things up, but it also goes stale. Sites that moved to a new server, pages that redirect oddly, or the occasional "this site can't be reached" on a URL that works fine on your phone - most of the time, it's the cache.

Flushing it takes one command: ipconfig /flushdns. Running it weekly means you clear out stale entries before they start causing problems you'd otherwise waste fifteen minutes troubleshooting.

In Task Scheduler, create a new basic task and set a weekly trigger for Sunday night. For the action, choose Start a program, enter cmd.exe in the program field, and put /c ipconfig /flushdns in the arguments field. The /c tells Command Prompt to run the command and close - without it, you'll end up with an empty cmd window sitting on your desktop after every run.

I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 08

You don't need elevated privileges for this one. DNS flushing works fine under a standard user account, so leave Run with highest privileges unchecked.

Just remember that if you use a VPN or custom DNS (like Cloudflare's 1.1.1.1 or NextDNS), flushing still works the same way - it clears Windows' local cache, not your provider's. The command is identical regardless of which resolver you're pointed at.

Auto-restarting flaky services spares me the full reboot process

Some Windows services misbehave in predictable ways. Windows Search (WSearch) gets sluggish and eats memory after a few days of uptime, and Print Spooler (Spooler) locks up often enough that "just restart the spooler" is basically a Windows meme. Rebooting the whole PC fixes them, but you lose your open tabs, your terminals, and whatever train of thought you were on.

Restarting a single service is faster and non-disruptive. The PowerShell command is one line: Restart-Service -Name WSearch -Force. You can swap WSearch for whichever service you're targeting.

For Task Scheduler, create a new task, set a daily trigger for 4 AM, and choose Start a program for the action. Enter powershell.exe as the program and -Command "Restart-Service -Name WSearch -Force" as the arguments. This one needs Run with highest privileges checked - restarting system services from a standard context will fail silently.

I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 09
I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 10
I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 11

If you want to restart multiple services in one task, you can chain them as -Command "Restart-Service -Name WSearch,Spooler -Force". One task, both services, two seconds total.

However, don't blanket-restart services you don't understand. Leave things like LanmanServer, RpcSs, and anything under CryptSvc as cycling them mid-day can break file sharing or crash other services that depend on them, or log you out. Stick to user-facing services you know are the problem, like Search, Spooler, or Windows Audio (Audiosrv) if your sound drops occasionally.

Disk Cleanup runs at night, so I never have to think about it

Disk Cleanup (cleanmgr.exe) is technically deprecated - Microsoft has been nudging people toward Storage Sense for years. But it's still bundled with Windows 11 25H2, it still works, and for scheduled cleanups, it's more flexible than Storage Sense because you can pick exactly which categories run.

The setup is two commands. First, open an admin Command Prompt and run cleanmgr /sageset:1. A dialog opens, listing everything Disk Cleanup can remove, including Windows Update leftovers, delivery optimization files, thumbnails, old upgrade files, and temporary internet files. Tick what you want cleaned and hit OK. The selections save as profile 1.

I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 12
I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 13

Second, schedule the actual run. In Task Scheduler, create a weekly task for 2 AM, set Start a program as the action, enter cleanmgr.exe, and put /sagerun:1 in the arguments. This runs the profile you just saved without needing any input. Tick Run with the highest privileges so it can clear system-level items.

I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 14
I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 15
I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 16
I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 17

On my machine, this reclaims somewhere between one and five gigabytes a month, mostly from Windows Update cleanup.

Storage Sense isn't a bad tool - it's actually better for casual cleanup because it runs automatically and manages the Recycle Bin and Downloads folder intelligently. But it doesn't let you script which categories get cleaned, which is the whole point of going the Task Scheduler route.

Launching my work apps every Monday morning gets my week started

For me, every Monday used to start the same way by opening the browser, launching Slack, opening the code editor, and finding the project folder. Five minutes of clicking before I'd done anything useful. Task Scheduler handles all of it now, and I just sit down at a workspace that's already set up.

The cleanest way to do it is by using a small batch file. Open Notepad, paste the following script, and save it as monday-start.bat:

start "" "chrome.exe" "https://mail.google.com" "https://calendar.google.com" timeout /t 3 /nobreak start "" "C:\Users\YourName\AppData\Local\slack\slack.exe" timeout /t 3 /nobreak start "" "C:\Program Files\Microsoft VS Code\Code.exe"

Make sure you use the correct path to each app. The timeout commands add a three-second gap between launches so the apps don't trip over each other fighting for focus.

I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 18

In Task Scheduler, create a new task with a weekly trigger set to Monday at your preferred start time - mine's 8:25 AM. Set the action to Start a program and point it at your .bat file. Leave Run with highest privileges unchecked, so apps launch under your normal user context.

I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 19
I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 20
I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 21
I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 22
I automated 5 annoying Windows maintenance tasks, and my PC basically runs itself 23

Don't enable "wake the computer to run this task" unless you actually want your PC to boot itself on Monday morning. Most people want their apps waiting for them when they sit down, not running unattended for hours.

Guides Editor

Email IconLinkedIn Icon

Yasir covers Windows, hardware, and privacy. A Windows user since XP and a Mechanical Engineer by training, he likes digging into the technical details most people skip over. His work has also been published on MakeUseOf, spanning everything from Windows optimizations to Excel deep dives. Outside of writing, he tinkers with his custom-built Ryzen rig, watches Impractical Jokers, and listens to way too much Lo-Fi.

Right of Reply

TweakTown offers all companies mentioned in this article, or those who have supplied review samples, the opportunity to respond. If your organization would like to provide a statement or clarification, we are happy to publish it here. To submit a response, please contact us.
Newsletter Subscription