This is something that I’ve been meaning to post for a while now. It’s a simple thing but can save you from having to open up the vSphere client or allow you to use this in a script. The commands listed below will allow you to place a ESX host in and out of Maintenance mode from the command line or Service Console (what ever you like to call it).
To enter maintenance mode run the following command
vimsh -n -e /hostsvc/maintenance_mode_enter
To exit maintenance mode run the following command
vimsh -n -e /hostsvc/maintenance_mode_exit
So your probably wondering how do I know if the host is in Maintenance Mode, here you go:
vimsh -n -e /hostsvc/runtimeinfo | grep inMaintenanceMode | awk ‘{print $3}’






Without grep:
vimsh -n -e /hostsvc/runtimeinfo 2>/dev/null | awk '/inMaintenanceMode/ { print $NF } '
Without grep:
vimsh -n -e /hostsvc/runtimeinfo 2>/dev/null | awk '/inMaintenanceMode/ { print $NF } '