Shutdown ESXi 6.7 with a script via SSH without entering maintenance mode

shutdownvmware-esxi

I'm trying to write a script that ssh's to an ESXi 6.7 and shuts down the host and also shuts down the VMs according to the current system shutdown policy.

I'm running Dell customized image ESXi 6.7 in a Dell R710 with a dual Xeon X5650 and 144GB RAM.

In fact what I want is the same that I can get with:

Shutdown via GUI

Shutdown via console

I have ssh enabled in the server.

I already tryed:

1) host_shutdown.sh (it just gets there indefinitely).

2) /bin/host_shutdown.sh (it to gets there indefinitely).

3) halt (shutdowns the server but it does not shuts down the VMs)

I also tried:

esxcli system shutdown poweroff --reason I_want_IT

but the system must be in maintenance mode and I want to do it without entering maintenance mode

I then discovered this thread here in Server Fault, but it does not work in my environment as it is PowerCLI and I'm want to run the script from a Raspberry Pi:

How do I shutdown the Host over ssh on ESXi 5 so it shuts down the guests properly?

I think I'm too dumb to discover on my own how to do it, because I presume it must be a simple thing to do.

Best Answer

I think I finally found the solution to this problem. After digging a lot I found that: /sbin/shutdown.sh && /sbin/poweroff will do the trick !!!

It shuts all VMs according to the current system startup policy and then it shuts the host down.