Learn What IT Pros Need to Know About Windows 11 - August 24th at 1 PM ET! Learn What IT Pros Need to Know About Windows 11 - August 24th at 1 PM ET!
VMware

Scripting the Startup and Shutdown of VMware Servers

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:

Sponsored Content

Read the Best Personal and Business Tech without Ads

Staying updated on what is happening in the technology sector is important to your career and your personal life but ads can make reading news, distracting. With Thurrott Premium, you can enjoy the best coverage in tech without the annoying ads.

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

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.

Related Topics:

BECOME A PETRI MEMBER:

Don't have a login but want to join the conversation? Sign up for a Petri Account

Register
Comments (0)

Leave a Reply

Register for Advanced Microsoft 365 Day!

GET-IT: Advanced Microsoft 365 1-Day Virtual Conference - Live August 24th!

Join us on Tuesday, August 24th and hear from Microsoft MVPs and industry experts about how to take advantage of Microsoft 365 at a technical level and dive deep into the features and functionality that will make your environment more secure and compliant.

RSVP Now

Sponsored By