19 April 2008

VmWare: vbscript to defrag & shrink all vmdk (batch)

If you have quite a lot of VM like me, defrag' & shrink of them is a pain, as it's one by one and manual.

So i wrote up a vbscript to do the job:

  • Search recursively in all folders from a root folder
  • defrag all vmdk found (vdiskmanager knows if it's possible or not)
  • shrink all vmdk found (vdiskmanager knows if it's possible or not)

fire up thevbscript with cscript, you will have vdiskmanager output:

vmware_compressor

You just need to change 2 things:

  • where is installed vmware workstation:
VmWareInstallFolder="C:\" & """" & "Program Files (x86)"
& """" & "\VMware\" & """" & "VMware Workstation" &
""""
  • Where are stored your VMDK :
VmdkRootFolder="F:\vmware"

My environnement:

  • Windows vista SP1 64 bit
  • VmWare Workstation 6

download: vmware_compressor