How to Schedule Defragmentation Across Multiple Drives on Windows 11
🔍 WiseChecker

How to Schedule Defragmentation Across Multiple Drives on Windows 11

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.

Symptom: You want different defragmentation/TRIM schedules per drive on a multi-drive Windows 11 PC.
Affects: Windows 11 with two or more attached drives.
Fix time: 10–20 minutes initial setup.

ADVERTISEMENT

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.

  1. Press Win + S, type Defragment, and open Defragment and Optimize Drives.
  2. Click Change settings at the bottom.
  3. Set Frequency to Weekly, and check Increase task priority if three consecutive scheduled runs are missed.
  4. Click Choose next to Drives. Uncheck any drive you don’t want to participate — typically USB externals or seldom-used HDDs.
  5. Save and close.

This runs once a week against the included drives. It’s the right level of control for most PCs.

ADVERTISEMENT

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.

  1. Turn off the built-in schedule first: in Optimize Drives → Change settings, uncheck Run on a schedule (recommended). This prevents conflicts.
  2. Open Task Scheduler. Right-click Task Scheduler Library and choose Create Task.
  3. Name it HDD Defrag — Drive D. Set Run whether user is logged on or not and Run with highest privileges.
  4. On Triggers, click New: Weekly, Sundays at 02:00.
  5. On Actions, click New. Program: defrag.exe. Arguments: D: /O /U /V (Optimize, show progress, verbose).
  6. 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.
  7. Click OK. Repeat the process for each additional drive with the matching defrag command:

      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.

  1. 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
  2. In Task Scheduler, set the Action to: Program powershell.exe, Arguments -ExecutionPolicy Bypass -File "C:\Scripts\defrag-and-log.ps1" -Drive D:.
  3. Add a second action that uses Send-MailMessage if 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.

ADVERTISEMENT