Hot Shot
Hot Shot

Powershell Stop-VMHost Question

I have a question about the functionality of the Powershell Stop-VMHost command.    I am writing a UPS shutdown script that will run on a Linux VM on the host to be shutdown.  The script will be triggered by a snmp trap from the Tripplite UPS when the battery gets down to 7 minutes remaining.   I'm able to shutdown all the VMs, except the one the script is running on, or at least issue a shutdown command to all of them (no point in waiting on completion as the power will fail shortly whether they finish in time or not).   The final two commands in the script are to shutdown the host and shutdown the VM the script is running on.  I'm going to issue the host shutdown first in case issuing the shutdown to the VM running the script first causes it to shutdown before the command to shutdown the host could be issued.


My question concerns what the -Force option really does.   I've read conflicting things, and maybe it does both.   I've read that it allows the shutdown to be done without the host going into maintenance mode, which is what I want as I want the VMs to come back up automatically after the power comes back on, which they won't if the host is in maintenance mode; but I've also read that it just terminates (i.e. powers off) any running VMs rather than waiting for a graceful shutdown, which I don't really want.  Also I've read that if you don't use -Force and the host isn't in maintenance mode a prompt message comes out like it would if you did a shutdown from the console not in maintenance mode, which of course I absolutely don't want in a UPS shutdown scenario when nobody will be there to answer.   The documentation isn't clear on how -Confirm, -Force, and maintenance mode interact with each other.     


What I'd like to have happen is to give the VMs all the time remaining if necessary before the power goes off for them to gracefully shutdown, rather than arbitrarily killing them if there is still power available.  From what I've seen it doesn't seem that ESXi itself has a problem with being hard powered off (i.e. it doesn't seem to have data structures of its own in memory that need to be flushed or risk having it not startup correctly the next time if it shuts down hard).   If that's actually the case I could simply not issue the host shutdown command at all and just leave it running until the battery dies, which would also have the effect of giving any VMs still in shutdown the maximum amount of time to actually shutdown and only give up on them when the battery dies.   On the other hand, if I could tell ESXi to shutdown only after the last VM has gracefully shutdown, not hard power them off, and not prompt if not in maintenance mode, I think that would be the best possible situation, assuming that there aren't issues with ESXi itself going down hard if the battery runs out first.   


0 Kudos
0 Replies