Scripting the Startup and Shutdown of VMware Servers

Posted on January 8, 2009 by David Davis in VMware with 0 Comments

In using VMware Server, sooner or later you will have a need to script the startup and shutdown of VMware Servers. You may want to do this for backup purposes or just to be able to run a script that can quickly stop or start virtual servers without bring up the VMware administrative application. Lets find out how to do this…

The vmware-cmd Command

Located in the default install directory of VMware Server is the VMware Server directory. Normally, this is in:

C:\Program Files\VMware\VMware Server

In this directory youll see vmware-cmd. This is a command line utility that can perform all types of command line VMware functions. For example, get the state of a server, stop a server, start a server, reset & suspend servers, and a long list of other functions. Here is the command line help information for vmware-cmd:

Also, here is the output in text format:

vmware-cmd help info

Starting up Servers with vmware-cmd

A common use for the vmware-cmd CLI tool is to start and stop virtual servers. You can do this by manually typing the required information at the command line or you can write a BAT (batch) file that can script this for you. If you think that you may do this more than once, writing a batch file is the best way to go because it doesnt take much more effort beyond entering the commands at the CLI and it can be run again and again. Also, the batch file is a great way to go because the required parameter to use vmware-cmd is the exact patch to the VMX file for the virtual machine being started/stopped and this path can be very long.

What I have done is used notepad to write a batch file to start my two virtual machines. The syntax looks like this:

vmware-cmd {exact path to VMX file} start

Sponsored

Sponsored
Note that you must be in the path where the vmware-cmd program is or your script must provide the exact path. This is why I do a cd to the proper directory before running the command.

This is done for each virtual machine.

Here is a sample script that you can open, download, and modify for your own needs.

StartVMS.zip

Here is what it looks like when it is run.

An output of “start() = 1” means that the start was a success. As long as the virtual machines are already stopped, you shouldnt have any trouble starting them up.

Shutting Down Servers With vmware-cmd

With the VMware Guest OSs started, I copied my batch file called startvms.bat and renamed it stopvms.bat. Then, I used notepad to replace the word start with stop. The syntax looks like this:

vmware-cmd {exact path to VMX file} stop

This is done for each virtual machine.

Here is a sample script that you can open, download, and modify for your own needs.

StopVMS.zip

Here is what it looks like when it is run.

Notice what happened here. I was able to successfully stop second virtual machine (see the stop = 1 code) but could not stop the first machine. This is because the VMware Tools have not been installed on the first virtual machine. You must install these tools to make the vmware-cmd work. Thus, this first machine is still running.

For more information on VMware Scripting, see this book on Scripting VMware.

In summary, the vmware-cmd program is a powerful program (and there are other command line vmware tools). This program is an excellent tool to script the startup and shutdown of virtual machines. Commonly, scripts like this are used for backup purposes where you want to stop all virtual machines, perform a full backup, then start all virtual machines after the backup.

To learn how to download and install VMware Server, see our article on How to Install VMware.

Sponsored