Quick fix: Open Optimize Drives, click Change settings, then click Choose next to the schedule to enable optimization for each drive individually. For fine-grained control across multiple drives at different times, use defrag.exe with Task Scheduler.
Windows 11 ships with a single global schedule for defragmentation and TRIM. Every drive runs on the same weekly cadence whether it’s a fast NVMe SSD, an old HDD used for archives, or a USB external. For a PC with mixed storage, the global schedule is suboptimal — the HDD wants weekly defrag at a quiet time, the SSD wants weekly TRIM, and the external doesn’t need either when it’s disconnected.
Affects: Windows 11 with two or more attached drives.
Fix time: 10–20 minutes initial setup.
What causes this
The Optimize Drives UI (dfrgui.exe) shows a single Scheduled optimization: On toggle. The underlying mechanism is a single scheduled task — \Microsoft\Windows\Defrag\ScheduledDefrag — that runs once a week and processes every “included” drive in sequence. The UI lets you exclude drives, but it doesn’t let you run different drives on different schedules.
The defrag.exe command-line tool has all the granularity you need: per-drive arguments, separate analyze/optimize/TRIM verbs, and quiet-mode flags suitable for unattended task runs. Pairing it with Task Scheduler gives you full per-drive control.
Method 1: Use the built-in schedule with per-drive inclusion
If you only need to choose which drives participate (not when they run), the GUI is enough.
- Press
Win + S, type Defragment, and open Defragment and Optimize Drives. - Click Change settings at the bottom.
- Set Frequency to Weekly, and check Increase task priority if three consecutive scheduled runs are missed.
- Click Choose next to Drives. Uncheck any drive you don’t want to participate — typically USB externals or seldom-used HDDs.
- Save and close.
This runs once a week against the included drives. It’s the right level of control for most PCs.
Method 2: Per-drive schedules via Task Scheduler + defrag.exe
When you want the HDD to defrag at 2 AM Sundays and the SSD to TRIM at 6 AM Wednesdays, build two scheduled tasks.
- Turn off the built-in schedule first: in Optimize Drives → Change settings, uncheck Run on a schedule (recommended). This prevents conflicts.
- Open Task Scheduler. Right-click Task Scheduler Library and choose Create Task.
- Name it HDD Defrag — Drive D. Set Run whether user is logged on or not and Run with highest privileges.
- On Triggers, click New: Weekly, Sundays at 02:00.
- On Actions, click New. Program:
defrag.exe. Arguments:D: /O /U /V(Optimize, show progress, verbose). - On Conditions, check Start the task only if the computer is on AC power for laptops, and Wake the computer to run this task if you want it to run even when sleeping.
- Click OK. Repeat the process for each additional drive with the matching
defragcommand:
SSD TRIM only:defrag.exe C: /L
Analyze without optimizing:defrag.exe E: /A
Full defrag (HDD only):defrag.exe D: /O
Run each task manually once (right-click → Run) to confirm it executes correctly. The Last Run Result column should read (0x0).
Method 3: PowerShell wrapper for reporting and email on completion
For server-like Windows 11 workstations where you want a log per run, wrap defrag in a PowerShell script.
- Create
C:\Scripts\defrag-and-log.ps1:
param([string]$Drive)
$log = “C:\Scripts\logs\defrag-$Drive-$(Get-Date -Format yyyyMMdd).log”
New-Item -ItemType Directory -Path (Split-Path $log) -Force | Out-Null
defrag.exe “$Drive” /O /V | Out-File $log -Encoding utf8 - In Task Scheduler, set the Action to: Program
powershell.exe, Arguments-ExecutionPolicy Bypass -File "C:\Scripts\defrag-and-log.ps1" -Drive D:. - Add a second action that uses
Send-MailMessageif you want email notifications (or post to a webhook).
The logs accumulate in a folder and tell you fragmentation trends over time. If a drive’s reported fragmentation never goes down, the drive is mostly full or has a failing controller.
How to verify the fix worked
- Run each task manually from Task Scheduler. Last Run Result reads 0x0.
- Open Optimize Drives. Each drive’s Last analyzed column should reflect the date of your manual run.
- Wait for the scheduled time and recheck the next day — the task should have fired automatically.
If none of these work
If a scheduled task fails with permission errors, the user account it runs as doesn’t have privilege on the target drive — change it to SYSTEM in the General tab. If defrag.exe returns “The disk cannot be optimized while it is in use,” another process has open handles — close backup software, antivirus full scans, and indexing services before retrying. For SSDs that report “Optimization not available,” the drive is set as offline or read-only in Disk Management; bring it online and clear the read-only flag with diskpart.
Bottom line: The GUI handles inclusion; Task Scheduler handles per-drive schedules. Build the second layer once and you stop having to think about disk maintenance forever.