Home > Windows Server Tips > Windows Server Monitoring and Management > Scripting Defrag in Windows Server 2003
Windows Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

WINDOWS SERVER MONITORING AND MANAGEMENT

Scripting Defrag in Windows Server 2003


Greg Ramsey, contributor, myITforum.com
08.24.2004
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Methods named "Defrag" and "DefragAnalysis" (part of Win32_Volume) are used to manage the Defrag utility included with Windows Server 2003.

Microsoft TechNet Script Center provides a nice example for Analyze Volume Defragmentation. The Technet Script Center Repository also has an example for how to defrag a Windows Server 2003 system using WMI:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "rootcimv2")
Set colVolumes = objWMIService.ExecQuery _
("Select * from Win32_Volume Where Name = 'D:\'")
For Each objVolume in colVolumes
errResult = objVolume.Defrag()
Next

Using this information, I created a script to enumerate all local hard drives and to check each one sequentially to see if it needs to be defragmented (TotalPercentFragmentation > 10%). If so, run Defrag. All information is written to the event log.

If you have any questions, you can e-mail the author o


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Windows Server Monitoring and Management
DirectAccess means 'always on' in Windows Server 2008 R2
Simple tools and techniques for finding Windows memory leaks
Top Windows server hardening standards and guidelines
Hyper-V gains new resiliency features with Windows Server 2008 R2
Troubleshooting Windows print spooler crashes
Windows server hardening: How much is enough?
Terminal Services grows up with Windows Server 2008 R2
Top five Server Core management tips for Windows 2008
Windows Server 2008 R2: Not your father's R2 upgrade
The bottom line on Microsoft Hyper-V

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


f this tip at ramseyg@hotmail.com.

ABOUT THE AUTHOR: Greg Ramsey has been working with SMS and desktop deployment since 1998. He currently works for a state agency in Columbus, Ohio. He has extensive knowledge in VBScript (including ADSI, WSH and WMI), Visual Basic, SMS Installer and good 'ol batch files. He is also the team lead for creating and managing both unattended builds and image-based installations using SysPrep.


This article first appeared in myITforum, the premier online destination for IT professionals responsible for managing their corporations' Microsoft Windows systems. The centerpiece of myITforum.com is a collection of member forums where IT professionals exchange technical tips, share their expertise and download utilities that help them better manage their Windows environments, specifically Microsoft Systems Management Server (SMS). To register for the site and sign up for the myITforum daily newsletter, click here.

Rate this Tip
To rate tips, you must be a member of SearchWindowsServer.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Server Room Design - Planning, Cooling, Maintenance
HomeTopicsBlogsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2004 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts