I have a terrible memory, which is why I think Windows Task Scheduler doesn’t get enough recognition for remembering to run tasks for me. Since it can call on all sorts of programs – including the mighty Windows PowerShell – Task Scheduler can be a great tool for keeping your system in tip-top shape. For me, it’s also the first step into the world of automation and PowerShell scripting. Here are a few ways I’ve set up my Windows 11 maintenance routine.
Setting up PowerShell and Task Scheduler
For more complex commands, we need to write PowerShell scripts. Before the system can run them, however, we’ll need to run this command in PowerShell:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
This allows the currently signed-in account to run locally created scripts without a digital signature.
I also keep my custom tasks in a new folder called System maintenance in Task Scheduler to stay organized. Alternatively, for tasks that share the same schedule, you can create a single scheduled task that runs all of them at once.
Windows Defender scans
Keep the bugs out
Windows Defender does a good job of protecting my system from nasty threats. Still, ever since I started experimenting with various self-hosting software, I think it warrants an explicit manual scan every week.
Here’s a tip: Task Scheduler already contains the scheduled tasks for most of Windows' tools. All they need is a trigger. Rather than creating a new task for this, I simply changed the scan frequency of Windows Defender to weekly. While I modified an existing entry here, most of the scripts in the rest of the article are written from scratch.
Schedule software updates with WinGet
Staying up-to-date gets even easier
Windows 11’s WinGet package manager has saved me so much time in keeping all my software up to date. I’ve scheduled it to run every Friday at midnight.
When creating the scheduled task, set it to launch a program. Enter powershell.exe in the Program/script field, and enter the following into the Add argument field:
winget upgrade --all --silent --accept-package-agreements --accept-source-agreements
Sometimes, the updated program will launch after the process completes. It was really annoying before I scheduled it to run during off hours only.
Launch the Windows Reliability Monitor
Check if there are any recurring issues
Windows' lesser-known Reliability Monitor rates the system’s stability on a scale of one to 10 based on how many errors it records. Having it launch every month helps me keep tabs on whether my system is having a persistent problem.
The command to launch the Windows Reliability Monitor is just one line. Add it into the Task Scheduler’s argument field without a script.
Start-Process perfmon -ArgumentList "/rel"
Clean up junk files
Free up storage space
I run Disk Cleanup regularly to remove junk files from my disk space. Launching it from the Start menu is already quick, but scheduling weekly cleanups means I don’t have to think about it at all.
Disk Cleanup presents a menu of items to delete every time it runs. Since I want to automate this process as much as possible, I set a default cleaning profile. This profile can be customized by entering cleanmgr.exe /sageset:1 in a Command Prompt window. Then, it’s just a matter of selecting from the list and hitting Save.
In Task Scheduler, set the routine to run cleanmgr.exe. In the arguments field, enter /sagerun:1 to specify the cleanup profile. When it runs, you won’t even notice it’s happening.
Clear local browser history
To improve privacy
I use Edge, Chrome, and Firefox in my daily workflow. Instead of opening every one of them and deleting their history individually, the Task Scheduler can take care of it for me.
For this script to work, the browser must be closed. The following script is for Google Chrome. To adapt this script for Microsoft Edge, Mozilla Firefox, and other browsers, just replace the file path with their specific history and cookie file locations.
#Script start
#Create an array of files to be removed
$historyFiles=@("Archived History", "History", "Top Sites", "Visited Links")
#Set the path to the Chrome folders containing said files. If there are multiple profiles in the browser, append their profile names after “\User Data’” in the path name.
$chromeSystemFolder = "$env:LOCALAPPDATA\Google\Chrome\User Data\System Profile"
$chromeProfileFolder= "$env:LOCALAPPDATA\Google\Chrome\User Data\Profile 1"
# Loop through the array and delete the files
foreach ($Item in $historyFiles)
{
$systemFilePath = Join-Path -Path $chromeSystemFolder -ChildPath $Item
$profileFilePath = Join-Path -Path $chromeProfileFolder -ChildPath $Item
Remove-Item -Path $systemFilePath -Force -ErrorAction SilentlyContinue
Remove-Item -Path $profileFilePath -Force -ErrorAction SilentlyContinue
}
Write-Host “Chrome history deleted.”
#Delete cookies stored in Chrome's “Network” folder
Remove-Item "$chromeSystemFolder\Network\Cookies" -Force -ErrorAction SilentlyContinue
Remove-Item "$chromeProfileFolder\Network\Cookies" -Force -ErrorAction SilentlyContinue
Write-Host “Chrome cookies deleted.”
#Wait for five seconds before closing the window
Start-sleep 5
Exit
#Script end
Clear system search history
Delete local search history too
Just like web browsers, the Windows file explorer also remembers your search history for local files as well as the run history. I clean them weekly using this command in a PowerShell script:
#script start
Remove-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\WordWheelQuery" -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU" -Name "*" -ErrorAction SilentlyContinue
Write-Host “File explorer history and run history deleted.”
Start-Sleep 5
Exit
#Script end
Check system health
Doesn't need to run frequently
It’s better to prevent a problem before it happens. Technically, the Windows System File Checker (sfc) and the Deployment Imaging System Management (DISM) tool are only needed when there’s a problem, like Windows updates consistently failing. Still, I run it once in a while to stay up to date on your PC’s health. I’ve rolled the following two commands into one PowerShell script and scheduled it to run every six months (in the schedule section, select repeat monthly and only tick off June).
#Script start
DISM /Online /Cleanup-image /RestoreHealth
Sfc /scannow
Write-host “System file scan complete”
#Add a pause so the results page stays on-screen
Pause
#Script end
Both sfc and DISM require admin-level privileges to run. In Task Scheduler, check off the option to run at the highest privileges when creating the task.
What else to do?
Task Scheduler is capable of much more than just running built-in Windows 11 functions. It can also be used to launch third-party apps. For example, in lieu of Disk Cleanup, I can schedule a run using BleachBit, or scan what’s hogging my storage space with WizTree alongside the Windows Reliability Monitor.
Other best practices for maintaining a healthy system include scheduling File History backups and creating system restore points. However, for backing up critical data, it may be better to use a third-party solution, as most of them have their own scheduling features. Finally, it’s a good idea to schedule these tasks to run during off-hours — take it from me, I’ve had to suffer through random Windows popping up in the middle of work or gaming sessions.
