The 2019 Lenovo I use for work has been feeling sluggish lately. Coincidentally, an ad appeared in the Lenovo software for something called Lenovo Smart Performance, which promised to keep my machine in peak condition by scanning 85 locations, checking connectivity settings, auditing the registry, and a dozen other things that sounded important.
I looked at the list and wondered if there was more I could already control to improve my laptop's performance without new hardware or paying for a subscription to that service, so I inputted the list of features -- some of which were clearly theater to make the list extra long -- into Claude to see what seemed worthwhile. It turned out that most of it was already supported by existing Windows applications and features, and Claude offered to create a PowerShell script for me to do the same thing. Well, sure.
![]() |
| Yes, I should have come up with a cooler name and ASCII art |
Optimize-System.ps1 is a PowerShell script I built with Claude that checks settings and runs maintenance on a Windows 11 machine. Here is what it does, in detail:
- Clears out junk files: temporary files, the Recycle Bin, cached thumbnails, leftover error reports, and files Windows downloaded for updates it has already applied
- Flushes the DNS cache, which is essentially Windows' address book for websites -- clearing it forces a fresh lookup and gets rid of stale entries
- Checks whether Windows is up to date and that the background services it depends on are actually running
- Runs Windows' built-in file integrity tools once a month to detect and repair any corrupted system files (Note: this will run for a while, but only once every 30 days.)
- Checks the physical health of your hard drive, how much memory is in use, how much disk space is left, and whether your error logs show anything unusual
- Audits a handful of Windows settings that are easy to overlook -- things like whether Windows is automatically cleaning up storage, whether a background service designed for older spinning hard drives is unnecessarily running on your newer solid state drive, and whether fast startup is enabled
Almost everything here is a thin wrapper around tools Windows already ships with. The riskiest thing it does is delete temporary files, and even that silently skips anything currently in use by another program. It deliberately stays away from the Windows registry and never changes a setting on its own.
One thing it flagged for me is that a background service called SysMain -- originally designed to speed up older spinning hard drives by preloading apps into memory -- was running on my solid state drive, where it provides no benefit and just quietly consumes RAM.
Running it once
Being cautious, I built it to have two modes.
Running it in ScanOnly mode shows you exactly what it would do and how much space it would free, without actually doing anything. You can then choose to proceed or exit. (Note: all relevant instructions are already built into both files I linked here.)
To run it as a one-off, save Optimize-System.ps1 to C:\Scripts and run this in PowerShell:
PowerShell -ExecutionPolicy Bypass -File "C:\Scripts\Optimize-System.ps1" -ScanOnly
Drop the `-ScanOnly` at the end to immediately execute the script, not just scan.
Running it, ongoing
You could schedule the script to run periodically, but I created a separate script that runs it automatically every time I reboot and log back into Windows: Optimize-Launcher.ps1
Similar to Optimize-System.ps1, save it to C:\Scripts\Optimize-Launcher.ps1.
Then run this once in PowerShell to register the launcher to run on boot and be prompted whether you'd like to run the optimizer or skip it:
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" `
-Argument "-ExecutionPolicy Bypass -WindowStyle Normal -File `"C:\Scripts\Optimize-Launcher.ps1`""
$trigger = New-ScheduledTaskTrigger -AtLogOn
$settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 120)
Register-ScheduledTask -TaskName "System Maintenance Prompt" `
-Action $action -Trigger $trigger -Settings $settings `
-RunLevel Highest -Description "Prompts at login to run weekly system maintenance"
![]() |
| Automatic PowerShell window prompt on Windows login |
I hope this helps somebody else!

