• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1493
  • Last Modified:

vSphere 4.1 guest vm shutdown script

I have a stand-alone ESX host running vSphere 4.1, without Virtual Center. The hosts have APC Powerchute configured to shutdown if the UPS runs low. One of the guests is on a subnet that cannot talk to the APC Network Management Card, so I cannot use PCNS. I need a script that will gracefully shut down one guest before the host shuts down. I have not done any scripting with vmware. Please indicate how to create the script and where it should be located. Should I have the APC network management card activate the script, or will the host automatically do it prior to shutting itself down?

Thanks in advance for your help.
2 Solutions
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
Why don't you use the Auto Shutdown Guests before Host Shutdown?

So when the ESX server gets the request to shutdown, it will delay and shutdown the Guests, before it turns off.


Otherwise scripts Have a look here


this perl script could be used


You will need a few additionals

I would recommend using the following, also VMware recommends the use of PowerCLI, which is PowerShell interface with vSphere-specific additions.


One of the simplest PowerCLI examples, and something which is actually extremely useful on its own, is the Get-VM cmdlet. Which lists VMs.

PowerCLI can be a bit overwhelming to use,  But it can be enhanced with a nice toolset and a library of preconfigured scripts to jump-start your mass changes, which is possible with PowerGUI

I believe the Auto shutdown feature in ESX should do what you need without the need for a script, as suggested by "hanccocka". Just log into vCenter, click on the host, then click the Configuration tab. In the 'Software' box, click the Virtual Machine Startup/Shutdown link. In the upper right click Properties. Follow the remaining steps from "hanccocka's" 1st link above.

If you do want a script, LucD (1 of *the* premier PowerCLI gurus; literally co-wrote the book on PowerCLI :) ) provides a script in the following link:

He gives you a script for a VM, or all VMs in a cluster.

Danny McDanielClinical Systems AnalystCommented:
Do you have the software(scripts) from APC that installs into the vma?

The vma is a vm appliance that runs on your host and would get the signal from the ups, then it would communicate with the host/VC to shutdown the guests.

I will post the link to the s/w if you can't find it.
fisher_kingAuthor Commented:
Thanks for the replies. I thought that the auto shutdown was only available through Virtual Center. But I prefer this to a script.
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
much easier than a script.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now