Windows server 2003 and Windows XP – How to shedule disk defragmenting

Posted by Mark | Posted in Scripting, Windows 2003, Windows XP | Posted on 07-07-2009

0




I`ll show you how to create very nice .bat script which will defragment your disks and generate report in log file.

This script was tested on Windows server 2003 or Windows XP machines.

Ok then, lets say you want to defragment C: and D: disks every Monday and Friday starting job at 10:00pm.

Also you want to store log file on C:\Tools folder.

OK, lets open notepad and copy paste this text:

@Ecxo off
Set logfile=C:\Tools\defrag.log
Echo Start %date%,%time% >>%logfile%
Echo *************************** >>%logfile%
Echo Defragmenting C: disk >>%logfile%
Echo. >>%logfile%
defrag.exe c: -f >>%logfile%
Echo *************************** >>%logfile%
Echo Defragmenting D: disk >>%logfile%
Echo. >>%logfile%
defrag.exe d: -f >>%logfile%
Echo *************************** >>%logfile%
Echo Finished %date%,%time% >>%logfile%
Echo *************************** >>%logfile%

Save this file as Defrag.bat and place it to C:\Tools folder

Now open command line and shedule defragmenting by typing:

at 10:00pm /every:M,F C:\Tools\Defrag.bat

defrag

Press “Enter”

And we are finished !

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • Reddit
  • StumbleUpon
  • Blogosphere News


Follow us on Twitter !
Follow us on Twitter!


Write a comment