How to Automate Disk Defragmentation Using Task Scheduler in Windows 11

Why Automate Disk Defragmentation?

For systems utilizing traditional Hard Disk Drives (HDDs), file fragmentation can significantly slow down read and write speeds over time. While Windows 11 includes built-in optimization, power users and system administrators often prefer to control exactly when and how defragmentation occurs using the Task Scheduler, ensuring it runs during off-hours without interrupting daily workflows.

Step 1: Open Task Scheduler

Click the Start button, type Task Scheduler, and press Enter to launch the application. This powerful Windows utility allows you to run commands and scripts automatically based on specific triggers.

Step 2: Create a Basic Task

In the right-hand Actions pane, click on Create Basic Task…. Give your task a descriptive name, such as “Weekly Disk Defrag”, and provide a brief description. Click Next.

Step 3: Set the Trigger Schedule

Choose how often you want the defragmentation to occur. For most HDDs, Weekly is optimal. Select Weekly, click Next, and specify the day and time (e.g., Sunday at 2:00 AM) when your computer is typically powered on but not in active use.

Step 4: Set the Action to Start a Program

On the Action screen, select Start a program and click Next. In the Program/script field, type:

defrag

In the Add arguments (optional) field, specify the drive you want to defragment and any additional flags. For example, to defragment the C: drive and consolidate free space, enter:

C: /O

Step 5: Review and Finish

Click Next to review your settings. Check the box that says Open the Properties dialog for this task when I click Finish. In the properties window, check Run with highest privileges to ensure the defrag command has the necessary administrator rights to execute. Click OK to save your automated task.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.