shutdown all vm’s and ESX

Just dropped the following short script in a topic on the VMTN Community. It shuts down every VM on the host and than the host itself, but it will enter maintenance mode first, just to be sure that no other vm’s get migrated to this host.

VMLIST=`vmware-cmd -l`
for config in ${VMLIST}
do
vmware-cmd ${VMLIST} stop trysoft
done
vimsh -n -e /hostsvc/maintenance_mode_enter
shutdown -h now

addition: thanks forbes for the trysoft addition.


5 Responses to “ shutdown all vm’s and ESX ”

  1. Hi Duncan, nice little script to have on each host.

    I would add the “trysoft” to this line:

    vmware-cmd ${VMLIST} stop trysoft

    otherwise I think it will just send a soft power-off to the VMs. I believe the trysoft will do the same, but then hard power-off if the soft doesn’t work.

    Forbes.

  2. Hi Duncan,

    Apologies if this is a somewhat uneducated question. Could this script be initiated by UPS software to power down the VMs and host in the event of a power failure?

    Regards,
    Andrew

  3. Yeah why not. But I wouldn’t place it into maintenance mode because VM’s will not startup when the server is in maintenance mode, or you would have to script a ” leave maintenance mode” .

  4. hi guys

    how do i execute this script? do i save it as a vbs and run it? How can i launch this from a batch file?

    Finally i didn’t quite understand what are the changes required ti implment Forbes’ suggestion.

    Many Thanks

    Christos

  5. These changes already have been made, and its a bash script so run it from the service console

Leave a Reply