While it is possible to manage VMware Workstation virtual machines remotely using the new HTML5 web-based WSX interface, there are also a number of use cases for going the command-line route. Let’s say that you want to write a script in Windows (Workstation runs in Linux too so most of this should apply but I didn’t test it) to manipulate virtual machines from your Workstation machine? You might assume that this isn’t too hard if the virtual machines you want to control are on the local Workstation machine but what if those virtual machines are running on a Mac in Fusion or what if they are running in the datacenter in VMware vSphere. Don’t fret; Workstation can handle all of this in a single command. – vmrun.
How to Install and Locate The vmrun Command
When you install VMware Workstation in Windows (I’ll just focus on Windows in this article), you’ll receive a number of command line tools (the .EXE files that you see in the graphic below). By default they are located in “C:\Program Files (x86)\VMware\VMware Workstation”. Some of these commands are used by VMware Workstation to do its job (like the vmnetdhcp.exe and the vmware-hostd.exe commands). Other commands just launch a graphical Workstation app such as vmware (which has some command line options) or vmnetcfg.exe (which launches the Workstation Virtual Network Editor).
However, there is at least one command in the VMware Workstation directory that can control virtual machines running in Workstation (locally), shared Workstation VMs (on another host running Workstation), VMware Fusion VMs, ESXi host VMs, vCenter managed VMs, and even VMs running in VMware Player. That command is vmrun.
As I said, the vmrun command (and the other Workstation executables mentioned above) are installed with Workstation in the “C:\Program Files (x86)\VMware\VMware Workstation”, as you see below:
Figure 1: VMware Workstation Executable Commands
Thus, anytime you run the vmrun command, you’ll either need to be in this folder, specify the full path, or you would have had to add this folder to your Windows PATH.
Starting Workstation VMs with the vmware command
The much less feature-rich command, vmware, can start VMs from the command line, start VMs and then go full screen, start VMs paused, and stop VMs when closing Workstation. Contrary to the vmrun command, the vmware command has just these limited number or uses.
Figure 2: Command Line Options for the vmware Command
Still, the vmware command is useful and I was able to use it to create an icon on my Windows desktop that I could double-click, start a virtual machine, and take it full screen. Once I had the command line, I created a Windows shortcut on my desktop (both for the vmware command and the vmrun command shortcut that I created in the next section). Here’s what the icons on the desktop looked like:
Figure 3: Windows Desktop Icons to Start VMs Using Scripts
The command line I used to create this icon is:
“C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe” -X “C:\[Path to VMX config file for the VM]”
Figure 4: Command Line Shortcut Using vmware to Start a VM
Since the vmware command was pretty limited in its functionality, I moved on to the vmrun command.
Using vmrun to Manage Workstation VMs
Included with Workstation, the vmrun command has much more functionality. The first test I used it for was to power on a virtual machine running on my local Workstation system. To get all the options, type vmrun /? and you’ll likely want to pipe it to more like this:
vmrun /? –help
From there you’ll get lengthy help information and you can page down by pressing the space bar.
What I did was to take that info and scroll up to the main command options:
Figure 5: vmrun Command Help Info
As you can see, the command is broken down into authentication, command, and parameters. Of particular interest are the authentication flags as it’s here that you specify the “-T” option for “host type”. The possible host types are: VMware Server (server/server1), Workstation (ws), VMware Workstation shared VMs (ws-shared), VMware Fusion (fusion), VMware ESX Server (esx), and vCenter Server (vc). Thus, the vmrun command can manipulate virtual machines running on any of these platforms.
As I said, in my case, I started with managing local Workstation virtual machines using the “ws” (for Workstation) server type option.
The exact command line option is:
Figure 6: vmrun Command Line String
That command started a VM on Workstation. I put it into a Windows desktop shortcut (you see the icon above) and used it to start a VM from my desktop with just a double click of my mouse. However, vmrun can be used to do much more than just start and stop virtual machines. You can also do thinks like:
- Snapshots – list, take a snapshots, delete snapshots, revert to a snapshot
- Guest OS – run program in the guest, check if a guest file exists, check if a dir exists, modify a shared folder, add/remove/enable/disable/disable a shared folder, list processes in guest, list directory in guest, and more
- vProbe commands
- General VM – List all running VMs, upgrade VM virtual hardware, list all installed VMware Tools, register/unregister a VM, delete a VM, clone a VM, and more
So, don’t stop at just starting and stopping virtual machines with vmrun as you’ve for the option to do much more.
Using vmrun to Manage vSphere VMs
One of the other things that vmrun can do is to manage virtual machines running in VMware vCenter or on a particular ESXi host. To do that, use (mostly) the same commands but use the host type of “T” for ESXi or “vc” for vCenter.
I took the same command line string above and tried to use it to power on a virtual machine running on a particular ESXi host. Here’s how…
First, I checked to ensure that the VM I was going to power on was already powered off (see my VM in the figure below).
Figure 7: vSphere VM Powered Off Before vmrun
Second, you’ll need the full path to the VMX file for the VM running in vSphere (including the datastore name). The easiest way to find that for your VM is to go into the VM’s Properties and in the General settings, look at where it says Virtual Machine Configuration File (as you see in the graphic below). Notice the host datastore name is at the start of that file path in brackets, like:
There will also need to be a space between the end of the datastore name and the start of he VMX configuration file name.
Figure 8: Finding the Virtual Machine VMX File and Datastore Name
With the full path to the VMX file in hand (including datastore name), you are ready to manipulate VMs in vSphere using vmrun.
Third, use the vmrun command with the VMX file path we found, like this:
Figure 9: Using vmrun to Power on a VM in vSphere
Once issued, the VM in vSphere quickly powered up. Here’s what it looked like from the vSphere Client:
Figure 10: vSphere VM Powered On via vmrun
You can also do things like list the running VMs in vSphere or vCenter or the “registered VMs” (which would be VMs that were registered with the host or vCenter but may or may not be powered on). Here’s how:
Figure 11: Listing Registered VMs with the vmrun Command
For more information on VMware Workstation, see the VMware Workstation Community.