Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1490
  • 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.

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

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