shutdown all vm’s and ESX
June 16th, 2008
Filed under: Scripting, VMware
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.
br>




June 16th, 2008 at 16:55
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.
July 15th, 2008 at 09:37
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
July 15th, 2008 at 10:39
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” .
September 10th, 2008 at 13:54
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
September 10th, 2008 at 14:38
These changes already have been made, and its a bash script so run it from the service console