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

What is “Inside Microsoft Teams”?

“Inside Microsoft Teams” is a webcast series, now in Season 4 for IT pros hosted by Microsoft Product Manager, Stephen Rose. Stephen & his guests comprised of customers, partners, and real-world experts share best practices of planning, deploying, adopting, managing, and securing Teams. You can watch any episode at your convenience, find resources, blogs, reviews of accessories certified for Teams, bonus clips, and information regarding upcoming live broadcasts. Our next episode, “Polaris Inc., and Microsoft Teams- Reinventing how we work and play” will be airing on Oct. 28th from 10-11am PST.

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

External Sharing and Guest User Access in Microsoft 365 and Teams

This eBook will dive into policy considerations you need to make when creating and managing guest user access to your Teams network, as well as the different layers of guest access and the common challenges that accompany a more complicated Microsoft 365 infrastructure.

You will learn:

  • Who should be allowed to be invited as a guest?
  • What type of guests should be able to access files in SharePoint and OneDrive?
  • How should guests be offboarded?
  • How should you determine who has access to sensitive information in your environment?

Sponsored by: