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:
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: