Using VIX to Defrag Windows Guests

Why? Because it’s awesome, that’s why. Below is an example, complete with syntax and screenshots on how to defragment a windows guest using VMware’s VIX.

Here is what it looked like before:

2009-01-09_1841

Here is the command used from the host where VIX is installed:

C:\Program Files\VMware\VMware VIX>vmrun -T esx -h https://vCenter.server.com/sdk
u domain\user -p pass -gu domain\user -gp pass runProgramInGuest
"[Local Storage] vm/vm.vmx" C:\windows\system32\defrag.exe -f c:

A bit of explanation is needed there. In the vmrun command the “-T esx” specifies we connect to an ESX host, and the “-h http://” gives the URL to the SDK of either the host, or in this case, the vCenter (Virtual Center) that the host belongs to. The next sets of parameters specify a user on the vCenter, or ESX host “-u” & “-p” respectively. As well as a user and password for the guest “-gu” & “-gp”.

Next we specify that we want to run a program inside the guest “runProgramInGuest”, and then which guest to run it on “[Local Storage]… .vmx”

The last, and most important parts, are the actual command "C:\windows\system32\defrag.exe –f c:” I’ve found that it’s important to specify the entire path to the command you are accessing, as it seems VIX does not have visibility into your path variable.

So, now that we’ve done all that, what does our disk look like afterwards:

2009-01-09_1926

11 thoughts on “Using VIX to Defrag Windows Guests

Comments are closed.