• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 827
  • Last Modified:

Disk Defrag

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.
  • 5
  • 4
2 Solutions

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.

arraya1Author Commented:
i know how to create the GPO.  The problem is I am not even able to run Disk Defrag on the computer.
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
Try Again

If it still doesn't work try a different profile.  It may be a profile issue.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

arraya1Author Commented:
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="http://schemas.microsoft.com/win/2004/08/events/event">
    <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>
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
arraya1Author Commented:
System Restore would mess up Disk Defragmentor from working?  
If the system was not imaged correctly. When your calling disk defragmenter to run it's not sure of which volume to execute on.
arraya1Author Commented:
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
arraya1Author Commented:
after the SFC /SCANNOW was ran, the task was switched to a WinXP scheduled task and that allowed disk defrag to kick off proprely.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now