WMI Defrag Action

The WMI Defrag action allows you to analyse the fragmentation and perform a defragmentation of a logical drive via WMI.

The WMI Defrag only works on Windows 2003 and Windows Server "Longhorn" operating systems. To Defrag on other OS's, use the Defrag Disk Action action.

![](/images/actions-reference/windows-os/wmi-actions/WMI Defrag-Options.png")

Machine Name

Enter the name of the remote machine, or leave blank for localhost

Drive Letter

Select the drive letter. If you want to set this dynamically, set it in the BeforeAction script event. See below.

Behaviour

Select if you want to perform an analysis or a defragmentation

Force Defrag

If the volume doesn't require defragmentation, setting this option will force the defrag anyway

Put Defrag Required in variable

If performing an analysis, the recommendation will be set to this variable, true for defrag recommended

Put Analysis Report in variable

Select the variable to save the analysis report to. The report will also be output to the log.

You can set the various properties of the action via script. For example, to set the Drive Letter via script:


Where "TheDriveLetter" is a variable that has been set to a valid drive on the machine, in the format <DriveLetter>:

eg. E: or C: