Disk Defrag

Posted on 2011-10-05
Last Modified: 2012-05-12
I'm attempting to setup a scheduled task via GPO for a disk defrag of the C:\

My first step was to start off by running the following command with Administrator privilege to confirm disk defrag works on the machine properly, I ran the command:

defrag C: /U

When I do this on the PC I'm experiencing issues with I receive the first image labeled "Image1_No.PNG"

When this is ran and properly works the second image attached "Image2_Yes.PNG" is how it should look.

any suggestions?  there are no errors in the event logs or anything that I could find.
Question by:arraya1
    LVL 3

    Expert Comment


    Please try the following steps:

    Group Policy Preference Client Side Extensions are already built into windows 7.

    Create a GPO and navigate to:
    [Computer Configuration\Preferences\Control Panel Settings\Scheduled Tasks],
    Right-click in the right-panel, choose Scheduled Task (Windows Vista and later):

    1. type a name and choose SYSTEM account to run this task.
    2. Switch to Triggers tab, click New, choose Weekly (or any date you prefer), click OK.
    3. Switch to Action tab, click New, type "defrag.exe" in Program/script box, type "/C " in Add arguments box. Click OK. You can choose other parameters based on your need. Type defrag /? Get more information about this command.

    Another option is below.
    1. First, paste the below into a batch file. It will schedule a defrag on the C: drive every Sunday at 12:00 AM and run it under the SYSTEM account. Save it somewhere like “C:\defrag.bat”:
    schtasks.exe /create /SC WEEKLY /D SUN /TN Weekly-Defrag /TR “defrag %systemdrive% -f” /ST 00:00:00 /RU SYSTEM

    2. Open Server Management or use “gpedit.msc”. Expand the domain until you find the OU containing all client machines you want to include.

    3. Right-click the OU and choose “Create and Link a GPO Here…”. Name it “Weekly Defrag”.

    4. Right-click the new policy and Edit. Browse to Computer Configuration -> Windows Settings -> Scripts -> Startup.

    5. Double-click “Startup”. Click Add and browse to the location of your defrag.bat file. Leave Script Parameters blank and click OK.

    6. Run a “gpupdate /force” on a client PC. Once it finishes, verify that there is a new Weekly Defrag Scheduled Task. You can even run the new task to make sure it is going to work.

    All done! All machines in the above OU will run a scheduled weekly defrag. Give the machines up to an hour to update GPO automatically.


    Author Comment

    i know how to create the GPO.  The problem is I am not even able to run Disk Defrag on the computer.
    LVL 3

    Accepted Solution

    Ohh Sorry.  Try the following
    opened an Elevated Command Prompt (right click on Command Prompt and select Run as Administrator) and it ran correctly.

    If the above doesn't work
    Run the SFC /SCANNOW
    Try Again

    If it still doesn't work try a different profile.  It may be a profile issue.

    Author Comment

    Thanks, that worked, now I receive an error when the schedule task kicks off:

    Log Name:      Application
    Source:        Group Policy Scheduled Tasks
    Date:          10/6/2011 11:29:10 AM
    Event ID:      4098
    Task Category: (2)
    Level:         Warning
    Keywords:      Classic
    User:          SYSTEM
    The computer 'C:\ Disk Defrag' preference item in the 'IT Disk Defrag (TEST) {D36A19BE-A17C-4844-B8B0-ED71F4C079B2}' Group Policy object did not apply because it failed with error code '0x8007007b The filename, directory name, or volume label syntax is incorrect.' This error was suppressed.
    Event Xml:
    <Event xmlns="">
        <Provider Name="Group Policy Scheduled Tasks" />
        <EventID Qualifiers="34305">4098</EventID>
        <TimeCreated SystemTime="2011-10-06T15:29:10.000000000Z" />
        <Security UserID="S-1-5-18" />
        <Data>C:\ Disk Defrag</Data>
        <Data>IT Disk Defrag (TEST) {D36A19BE-A17C-4844-B8B0-ED71F4C079B2}</Data>
        <Data>0x8007007b The filename, directory name, or volume label syntax is incorrect.</Data>
    LVL 3

    Expert Comment

    Error: 0x8007007B - "the filename, directory name, or volume label syntax is incorrect". Is caused by faulty imaging by the original equipment manufacturer (OEM) that results in the presence of an invalid volume or occurs when the system is set to store restore points to a wrong path or location.

    Try the following:
    In system restore
    Deselect the "C: Missing" checkbox and select "Local Disk C:" to enable System Restore.

    Run a SFC

    Author Comment

    System Restore would mess up Disk Defragmentor from working?  
    LVL 3

    Assisted Solution

    If the system was not imaged correctly. When your calling disk defragmenter to run it's not sure of which volume to execute on.

    Author Comment

    ok, the scheduled task that it was running was specifying the C:\

    defrag c: /u

    I will give this a try and get back to you.  Thank you

    Author Closing Comment

    after the SFC /SCANNOW was ran, the task was switched to a WinXP scheduled task and that allowed disk defrag to kick off proprely.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    When you use the right mouse button (assuming you're right handed) to click something in Windows, you usually get what is called a "context menu".  It's called that because the items in the menu vary according to context, that is, according to where…
    New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
    Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
    The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now