VMware Cloud Community
zgrywusek
Contributor
Contributor

Script to shutdown or suspend VM's and then turn off Host

Hi, I have been looking for a script that would do the following:

- suspend all VM's residing on the host according to VM Startup and Shutdown predefined on the host

then

- turn the host off gracefully

I really need something right away, if someone helps me out I don't mind sending out $20 gift card. (for working script).

0 Kudos
25 Replies
zgrywusek
Contributor
Contributor

LucD, I really like your script but issue with running this script from another computer/server is problematic for us. As I've stated we have 70 branches, each branch has one ESXi host. If we put this script and trigger it to run from our corporate office that would work, but in case of ISP issues etc we won't be able to issue that command.

If we pre-define Startup/Shutdown in ESXi and only issue command like: 

Get-VMHost -server "ServerName" | Stop-VMHost -Force -Confirm:$false

Wouldn't ESXi first shut down gracefully VM's residing on it and then turn itself off? Bottom line we have to figure out how to run this command internally from within one of the VM's.

APC PowerChute does it when you have it installed on ESXi, I assume that is all based on scripts....

0 Kudos
LucD
Leadership
Leadership

If these are indeed standalone ESXi nodes then you could indeed use the Automatic startup/shutdown feature.
See also Edit Virtual Machine Startup and Shutdown Settings (vmware.com)

You should probably use the RunAsync switch on the Stop-VMHost cmdlet.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

zgrywusek
Contributor
Contributor

can you send me the whole command? Runasync?

Tags (1)
0 Kudos
LucD
Leadership
Leadership

You could do something like this

Get-VMHost -Name MyEsx |
Stop-VMHost -RunAsync -Confirm:$false


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
tractng
Enthusiast
Enthusiast


Would this work if the VM tools are out of date?

Also the Linux machines that don’t have VM tools would just not be effected  from the script?

 

TT

0 Kudos
DavidT5
Contributor
Contributor

Is there any final draft of the script I can try to run?
BTW: is there option to turn off esxi before the turn off the VMs? Because I want one of the vm's will trigger the shutdown process.

0 Kudos