Defrag your system once a month


Do not use this on SSD hard disks. It will crash your hard drive.

@echo off
schtasks.exe /create /SC MONTHLY /D TUE /TN Monthly-Defrag /TR “defrag %systemdrive% -f” /ST 12:15:00 /RU SYSTEM

1. First, paste the below into a batch file. It will schedule a defrag on the C: drive every Tuesday at 12:15 AM and run it under the SYSTEM account. Save it somewhere like “C:\defrag.bat”:

schtasks.exe /create /SC MONTHLY /D TUE /TN Monthly-Defrag /TR “defrag %systemdrive% -f” /ST 12:15: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