We dont very often do much server maintenance, especially on our centralised dev and file server boxes. Mostly we don’t have time, as a small team that goes through mountains of work its not a priority. Today I had 5 minutes (!) to actually see if there was a way to automate Disk Clean up and Disk Defragmenter in Windows XP / 2003. Lo and behold:
Disk Cleanup
Cleanmgr.exe can be scheduled to run. To do this, first open a command prompt (Start > Run > cmd > enter) and use the following command format:
So for a cleanup on c drive, lets use sageset 1 (you can number them however you want, use 1 for your c: drive, 2 for d:, 3 for e: etc)
and hit enter. This will start up the disk Cleanup window, in just the same way as if you launched it manually. It will prompt you to select which tasks you want performed during the disk cleanup. Go ahead and select the file types you want removed and click OK. Now you can schedule the disk cleanup task you just created by running the following command from the command line or Task Scheduler:
cleanmgr /sagerun:1
Defragment the Volume
You can use Defrag.exe to schedule defragmentation on a volume. The bonus here is that you dont have to be awake at 2am when your server is at its quietest to set off the defrag. Following this syntax:
we can set up a command line run that will defrag the c: drive and output results to a text file.
Now you can put this into the command line of a Scheduled task and set it up to run once a day/week/month at some ungodly hour so you dont have to set your alarm. Marvellous!