From Cygnus Alpha
Jump to: navigation, search

VMWare ESXi VSphere CLI

Get the stuff


sudo apt-get install libssl-dev
sudo apt-get install libxml-libxml-perl
tar -zxvf VMware-vSphere-CLI-4.1.0-254719.i386.tar.gz
cd vmware-vsphere-cli-distrib/
sudo ./vmware-install.pl

I installed in /usr/local/bin

YMMV obv. You may need to install more libraries.


Create a session file

Optional. If you use a session, you need to use --sessionfile in each command instead of username / password

  • apps/session/save_session.pl --server --savesessionfile /tmp/session
apps/session/save_session.pl --server --savesessionfile /tmp/session
Enter username: root
Enter password: 
Session information saved.

List vmhosts on the server:

  • vmware-cmd -U root -P <password> --server -l
  • vmware-cmd --sessionfile /tmp/session -l
jamesb@VMX-NODE0:~/vmware-vsphere-cli-distrib$ vmware-cmd -U root -P ******* --server -l

Get ESXi Server info

  • vicfg-hostops --username root --password <password> --server --operation info
  • vicfg-hostops --sessionfile /tmp/session --operation info
jamesb@VMX-NODE0:~/vmware-vsphere-cli-distrib$ vicfg-hostops --username root --password ******** --server --operation info

Host Name            : vmhost.example.co.uk
Manufacturer         : HP
Model                : ProLiant DL360 G5
Processor Type       : Intel(R) Xeon(R) CPU           E5320  @ 1.86GHz
CPU Cores            : 8 CPUs x 1866 GHz
Memory Capacity      : 4093.71875 MB
VMotion Enabled      : no
In Maintenance Mode  : no
Last Boot Time       : 2011-07-26T16:57:25.643553Z

Shutdown ESXi Server

  • vicfg-hostops --username root --password <password> --server --operation shutdown --force

nb. --force shuts down all running virtual machines

Reboot ESXi Server

  • vicfg-hostops --username root --password <password> --server --operation reboot --force

nb. --force shuts down all running virtual machines

Powering ON a Virtual Machine

  • vmware-cmd -H <vc_system> -U <user> -P <password> --vihost <esx_host>

/vmfs/volumes/Storage2/testvm/testvm.vmx start soft

Powering OFF a Virtual Machine

  • vmware-cmd -H <vc_system> -U <user> -P <password> --vihost <esx_host>

/vmfs/volumes/Storage2/testvm/testvm.vmx stop soft

Suspend a Virtual Machine

  • vmware-cmd -H <vc_system> -U <user> -P <password> --vihost <esx_host>

/vmfs/volumes/Storage2/testvm/testvm.vmx suspend soft

Reset a Virtual Machine

  • vmware-cmd -H <vc_system> -U <user> -P <password> --vihost <esx_host>

/vmfs/volumes/Storage2/testvm/testvm.vmx reset soft

Convert VMWare image to VirtualBox


  • Convert to raw bin
qemu-img convert MyVMWareMachine.vmdk raw-file.bin
  • Convert to VirtualBox image
VBoxManage convertdd raw-file.bin MyVirtualBoxMachine.vdi
  • Run Virtualbox and add the image to the library then Virtualbox again and compact the image with:
VBoxManage modifyvdi MyVirtualBoxMachine.vdi compact

And back to vmdk

qemu-img convert MyVirtualBoxMachine.vdi -O vmdk MyVMWareMachine.vmdk

External Documentation