Using vCLI (vMA) or PowerCLI for ESXi server maintenance mode

Just a quick post (mostly for documentations sake) to highlight on how to take your ESX(i) boxes into and out of maintenance mode using either VMware vCLI/vMA or VMware PowerCLI (Powershell)

This can be handy if you have a whole bunch of new blades to apply drivers to, or ESXi firmware updates via vihostupdate. You can put all this in a script to make your admin life a little easier.

Using vCLI installed on your workstation or via the vMA

You can enter and exit maintenance mode as well as reboot individual ESX hosts:

vicfg-hostops --server youresxservername --operation enter
vicfg-hostops --server youresxservername --operation exit
vicfg-hostops --server youresxservername --operation reboot

Example: vicfg-hostops --server esx01.domain.local --operation enter

Or you can do it against an entire cluster (useful if all your new servers are in a new cluster)

vicfg-hostops --server yourvcenterserver --cluster "yourcluster" --operation enter
vicfg-hostops --server yourvcenterserver --cluster "yourcluster" --operation exit

Example: vicfg-hostops --server vcenter41.domain.local --cluster "ProdCluster" --operation enter

Similar things from the Powershell side

#Connect to your vcenter server
connect-viserver -server yourvcenterservername

#Put ESX host into maintenance mode
Set-VMHost -vmhost youresxservername -state maintenance

#Take ESX host out of maintenance mode
Set-VMHost -vmhost youresxservername -state connected

#Reboot your ESX host  (must be in maintenance mode or also use -force in the command)
Restart-VMHost -vmhost youresxservername