How to Use vim-cmd to Power on vSphere VMs without Windows or the vSphere Client
Most of the time I run a VERY small vSphere lab comprised of just one host and a NAS, simply to keep the power requirements down and the electricity bill low. While I have a large UPS on the lab, recently, the power went out for an extended period of time. Later, I went to connect to my vCenter server and run the vSphere Client for Windows over RDP from my Mac and found that I couldn’t connect. As I use a Mac and have actually run out of space on my SSD for Fusion virtual machines (like the Windows 8 VM I used to use with the vSphere Client for Windows inside), I was planning on running the vSphere Client for Windows over RDP.
Today, I have only two Macs and the 5 vSphere/ESXi hosts in my lab environment. With only Mac systems and no Windows VMs running, I realized that I had no way to control the Windows VMs in the lab to get them running and, thus, manage the ESXi host (and thus to get Windows AD/DNS and vCenter powered on). Alternatively, I could have built a Windows VM in Fusion on my Mac (in the little SSD space I have left) or I could have taken my Mac to my office (in another building), connected my USB3 external drive, where I have a Fusion VM with Windows 8 and the vSphere Client, and managed the lab from there. However, at 5am while sitting in my pajamas in bed, I wasn’t interested in either of those.
Fortunately, I had the ESXi host set to power on automatically AND I had enabled the ESXi command line for remote SSH access on the host so using SSH to power on the VMs seemed like a great idea.
Initially, I thought that I could use the esxcli command to power on the Windwows AD/DNS machine and the vCenter Server appliance. When that didn’t work, I tried vmrun (which didn’t work either). As it turns out, once I did a quick Google, it’s the vim-cmd that the VMware KB article recommended for me to power on the VMs.
The syntax to use vim-cmd to
- list all registered virtual machines
- check VM power state and
- power on a virtual machine
is:
/vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # vim-cmd vmsvc/getallvms Vmid Name File Guest OS Version Annotation 1 AD-DNS1 [ESX9-local] AD-DNS1/AD-DNS1.vmx windows8Server64Guest vmx-08 2 vCSA-5.1 [ESX9-local] vCSA-5.1/vCSA-5.1.vmx sles11_64Guest vmx-07 VMware vCenter Server Appliance Version 5.1 of VC running on SLES 11 3 Win8-2 [ESX9-local] Win8-2/Win8-2.vmx windows8_64Guest vmx-08 4 Win8-1 [ESX9-local] Win8-1/Win8-1.vmx windows8_64Guest vmx-08 7 vCSA-5.5 [ESX9-local] vCSA-5.5/vCSA-5.5.vmx sles11_64Guest vmx-07 VMware vCenter Server Appliance Version 5.5 of VC running on SLES 11 /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # vim-cmd vmsvc/power.getstate 1 Retrieved runtime info Powered off /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # vim-cmd vmsvc/power.on 1
So how do I prevent this from happening in the future? What I should have done is to configure automatic virtual machine startup on the ESXi host. To do this, once one of the Windows VMs was booted, I RDP’ed to it, ran the vSphere client, connected to the ESXi host, went into the host Configuration and then into Virtual Machine Startup / Shutdown to set the Windows AD/DNS VM and vCenter to automatically power on when the host powers on, like this:

Figure 1.0 – ESXI Auto VM Startup Configuration

Figure 2.0 – ESXI Auto VM Startup Configuration
With my virtual machines powered on, I could then use my Mac’s web browser to access the web-based vSphere Client, like this:

Figure 3.0 – ESXI Auto VM Startup Configuration
If you are interested, here’s what my entire SSH process was:
Davids-MacBook-Pro-4:~ david$ ssh root@10.0.1.19 Password: The time and date of this login have been sent to the system logs. VMware offers supported, powerful system administration tools. Please see www.vmware.com/go/sysadmintools for details. The ESXi Shell can be disabled by an administrative user. See the vSphere Security documentation for more information. ~ # ~ # ~ # esxcli Usage: esxcli [options] {namespace}+ {cmd} [cmd options] Options: --formatter=FORMATTER Override the formatter to use for a given command. Available formatter: xml, csv, keyvalue --debug Enable debug or internal use options --version Display version information for the script -?, --help Display usage information for the script Available Namespaces: device Device manager commands esxcli Commands that operate on the esxcli system itself allowing users to get additional information. fcoe VMware FCOE commands. graphics VMware graphics commands. hardware VMKernel hardware properties and commands for configuring hardware. iscsi VMware iSCSI commands. network Operations that pertain to the maintenance of networking on an ESX host. This includes a wide variety of commands to manipulate virtual networking components (vswitch, portgroup, etc) as well as local host IP, DNS and general host networking settings. sched VMKernel system properties and commands for configuring scheduling related functionality. software Manage the ESXi software image and packages storage VMware storage commands. system VMKernel system properties and commands for configuring properties of the kernel core system. vm A small number of operations that allow a user to Control Virtual Machine operations. vsan VMware VSAN commands. ~ # esxcli vm Usage: esxcli vm {cmd} [cmd options] Available Namespaces: process Operations on running virtual machine processes ~ # pwd / ~ # ls altbootbank lib64 sbin var bin local.tgz scratch vmfs bootbank locker store vmimages bootpart.gz mbr tardisks vmupgrade dev opt tardisks.noauto etc proc tmp lib productLocker usr ~ # cd vmfs /vmfs # ls devices volumes /vmfs # cd volumes/ /vmfs/volumes # ls 3df9e97d-5447d963-da5a-8d26c68d4d18 96707a74-997182ad-48f2-7c71cd2d3364 51ce0a88-0157c442-659c-d067e5ed1f8d ESX9-local 52081c47-67f0d878-e27f-d067e5ed1f8d SYN-NFS-1 52081c4e-b2835f20-4c84-d067e5ed1f8d vsan:52241b7524efc10e-1dbab6469991884f 8b492681-34696aad vsanDatastore /vmfs/volumes # cd ESX9-local/ /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d # ls AD-DNS1 Win8-2 NexentaStor-Community-3.1.3.5-GA.iso vCSA-5.1 Win8-1 vCSA-5.5 /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d # cd AD-DNS1/ /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # ls AD-DNS1-165ef98e.vswp AD-DNS1.vmxf AD-DNS1-flat.vmdk AD-DNS1.vmx~ AD-DNS1.nvram vmware-1.log AD-DNS1.vmdk vmware-2.log AD-DNS1.vmsd vmware.log AD-DNS1.vmx vmx-AD-DNS1-375323022-1.vswp AD-DNS1.vmx.lck /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # ls *.vmx AD-DNS1.vmx /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # vmrun -sh: vmrun: not found /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # vim-cmd Commands available under /: hbrsvc/ internalsvc/ solo/ vmsvc/ hostsvc/ proxysvc/ vimsvc/ help /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # vim-cmd vmsvc/getstate Invalid command 'vmsvc/getstate'. /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # vim-cmd vmsvc/getallvms Vmid Name File Guest OS Version Annotation 1 AD-DNS1 [ESX9-local] AD-DNS1/AD-DNS1.vmx windows8Server64Guest vmx-08 2 vCSA-5.1 [ESX9-local] vCSA-5.1/vCSA-5.1.vmx sles11_64Guest vmx-07 VMware vCenter Server Appliance Version 5.1 of VC running on SLES 11 3 Win8-2 [ESX9-local] Win8-2/Win8-2.vmx windows8_64Guest vmx-08 4 Win8-1 [ESX9-local] Win8-1/Win8-1.vmx windows8_64Guest vmx-08 7 vCSA-5.5 [ESX9-local] vCSA-5.5/vCSA-5.5.vmx sles11_64Guest vmx-07 VMware vCenter Server Appliance Version 5.5 of VC running on SLES 11 /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # vim-cmd vmsvc/power.getstate 1 Retrieved runtime info Powered off /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # vim-cmd vmsvc/power.on 1 Powering on VM: /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # vim-cmd vmsvc/power.on 7 Powering on VM: /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # vim-cmd vmsvc/power.getstate 1 Retrieved runtime info Powered on /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 # vim-cmd vmsvc/power.getstate 7 Retrieved runtime info Powered on /vmfs/volumes/51ce0a88-0157c442-659c-d067e5ed1f8d/AD-DNS1 #
-
been there my friend
is vmware ever gonna realize that geeks also love mac/linux?Im a little bit picky with mac mac air, and dont want to install fusion only for vmware or xen server clients.
I think that is the only think i cannot do from mac os.so, I’ve have to push my mind a little bit and remember the xe vm command and vim cmd.
its not that bad.
now, when you need to import, export, etc a vm… that’s another story.
keep the good work! enjoying your content.
Comments