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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 7

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.