Scheduled Disk Defragmenter for multiple drives on Server 2008 R2

As you may know, the default Disk Defragmenter utility built into the Server 2008 interface allows you to schedule a task for defragmenting disks.  However, the catch is that you can only create one scheduled task item using this interface.  This would work fine if you have less than a few drives that are not actively used but in my case, this server has 13 drives that are used by hundreds of users on a daily basis.

So, I need to setup a task item that will run nightly to defrag only a few drives at a time.

Follow along as I walk through how to schedule multiple tasks given the limitation of the Disk Defragmenter gui.

First, let’s do a quick overview:

  1. Setup a Scheduled Task item in the Disk Defragmenter console
  2. Export the Task item to use for other tasks
  3. Get the GUID of the drives
  4. Import the Task item template and modify for each set of drives
  5. Monitor and correct course along the way

Setup a boilerplate Scheduled Task item

The easiest way to do this is through the Disk Defragmenter console since you probably already have it open.

Disk Defragmenter Console

Click on the Configure schedule button and adjust the schedule as you wish.  Remember, this is the boilerplate but consider setting this up so that it will run along with the other tasks we’ll schedule.  No sense in double handling the work.

Disk Defragmenter Schedule Console

Now, click the Select disks button to select the disks you want to include.  I recommend selecting either one disk or just a few so you get the idea of what the task will look like once exported.

Disk Defragmenter Select Disks Console

In my case, I only selected one drive.  Click OK then OK on the Modify Schedule window and you can close the Disk Defragmenter window now.

Export the Task item to use for other tasks

Now, open up the Task Scheduler console and browse down in the tree on the left to Task Schedule Library < Microsoft < Windows < Defrag and notice the scheduled task you just created.
Click on the task to see details.

Task Scheduler Console

We’re going to Export this item and then Import it again.  Too bad there is not a Duplicate function here.

Start by Right-Clicking on the task item.

Task Scheduler Console-right click task

Browse to a location where you want to save this configuration file.  I prefer to keep these centrally located for future reference and documentation but for the sake of this article, I will save the file in my local IT folder.

Task Scheduler Console-export task

Now that the export process is complete, we can Import the file back into the Task Scheduler Console.

Right-click anywhere in the Task list areas to bring up the action menu.

Task Scheduler Console-right click Import

Select the file you just saved and then click OK.

You should now see a Create Task window.  Notice the Name of the Task and change it accordingly to something that describes the task briefly.  Perhaps the name of the drive you want to defrag.

Task Scheduler Console-Imported Task

Next, click the Triggers tab to modify the schedule as needed.

Task Scheduler Console-Imported Task-Triggers

Select the Trigger item (in this case it is called Weekly) and then click the Edit button or Double-Click the trigger item to edit.

Task Scheduler Console-Imported Task-Triggers-Edit Trigger

Adjust the schedule as needed for the drives you have in mind then click OK to close the window.

Next, click the Actions tab which is where we get into the meat of this project.

Task Scheduler Console-Imported Task-Actions

Double-Click the Action item or select the item and click Edit.

Task Scheduler Console-Imported Task-Actions-edit action

Everything here will remain the same except for the “Add arguments (optional):” value.

If you’ll notice, the item looks something like this:  \\?\Volume{9d573eb6-aa70-11e1-9b4f-0050563b9b3c}\

This is where we need the GUID for each drive.

Get the GUID of the drives

You will need to know the GUID for each of the drives you want included in a Task.  Check out my post on “How to get the volume GUID of a drive” to see how to do this quickly.

Now that we have the GUID, let’s get to work on setting up multiple task items.

You can do this by simply copy & paste function into the value as you saw above, save then import the template again and repeat.  But in this case, I want to do it without having to load all the gui windows.  So I’m going to edit the actual exported file itself.

Import the Task item template and modify for each set of drives

With a list of the GUIDs in hand and access to the exported Task item we’re ready to get started.

We are going to look at changing only two parts of the file then save it as a new file:

  • Description
  • Day the task should fire off and
  • the Volume(s) where defragging will occur.

Let’s start by opening the XML file that was saved when we exported the first task item.

Once open, notice the <Description> parameter about six lines down from the top.  Rename this as desired.

Next, search for the parameter “<DaysOfWeek>” (without the quotation marks).  You should notice the default day that was setup in the Scheduled Task item.

In my case, the day is “<Wednesday />” but I am going to change it to “<Monday />”.  You can change this value to whatever you want.

Finally, search for “<Command>%windir%\system32\defrag.exe</Command>”.  Right below this tag, you should see a tag called “<Arguments>”.  This is where we’ll identify the drive(s) (GUID) we want to be defragged.


In my case, I’m going to add multiple drives to this task so I’ll need to enter each GUID per line.


Now that we’re finished, I’m going to save this file as a different name that will reflect the drives I’ve configured.

The last step is to Import the file into the Task Scheduler console just like we did before.


Double check your settings after you’ve imported the item and then check up on it after it’s schedule run time to make sure everything fired off correctly.

Side Notes

There are other configurations you can change in the XML file that will save you time.  Spend some time getting familiar with the different settings to see how you can create all kinds of scheduled items on the fly.

[fusion_builder_container hundred_percent=”yes” overflow=”visible”][fusion_builder_row][fusion_builder_column type=”1_1″ background_position=”left top” background_color=”” border_size=”” border_color=”” border_style=”solid” spacing=”yes” background_image=”” background_repeat=”no-repeat” padding=”” margin_top=”0px” margin_bottom=”0px” class=”” id=”” animation_type=”” animation_speed=”0.3″ animation_direction=”left” hide_on_mobile=”no” center_content=”no” min_height=”none”][author_info][/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]

1 thought on “Scheduled Disk Defragmenter for multiple drives on Server 2008 R2”

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: