2007-11-27

PoMaDiDe - Poor Man's Disk Defragmentation

As a long time user of Diskeeper, which I've always recommended as a product, I've never had to think about disk defragmentation and maintenance.

However when tweaking a new machine that I'll be using for a while at a friend's company, I decided to just automate the new (for XP), CLI disk defragmenter defrag.exe.

I simply setup a scheduled task to run daily at 4am.  It executes the following batch file:

DailyDiskDefrag.bat

@echo off
date /t >> %LogPath%\Misc\DailyDiskDefrag.log
time /t >> %LogPath%\Misc\DailyDiskDefrag.log
C:\WINDOWS\system32\defrag.exe c: -v >> %LogPath%\Misc\DailyDiskDefrag.log 2>&1

I have a system variable set for LogPath to "C:\Windows\system32\LogFiles", so this will append to a file in the 'Misc' directory called 'DailyDiskDefrag.log'.  For those of you windows n00bs that never had to experience the pain joy of old skool batch programming, '2>&1' just redirects stderr back to stdout.

I'm sure there is a much cooler way to do this in PowerShell, sadly I'm not l33t enough at this stage of my life to pull that off.  Perhaps one day I'll look into all this PowerShell goodness.

Also, FWIW, I changed the default log location for the Scheduled Tasks service using this post from the mvps.org site.

No comments: