To complete some specific administration tasks, you might need to activate maintenance mode for a host. On vSphere, you can activate maintenance mode by using the Set-VMHost cmdlet.

Connect to a vSphere server.


Save the Host host object as a variable.

$host = Get-VMHost -Name Host

Get the cluster to which Host belongs and save the cluster object as a variable.

$hostCluster = Get-Cluster -VMHost $host

Start a task that activates maintenance mode for the Host host and save the task object as a variable.

$updateHostTask = Set-VMHost -VMHost $host -State "Maintenance" -RunAsync

If the host is not automated or is partially automated and has powered-on virtual machines running on it, you must specify the RunAsync parameter and wait until all powered-on virtual machines are relocated or powered off before applying DRS recommendations.


Get and apply the recommendations generated by DRS.

Get-DrsRecommendation -Cluster $hostCluster | where {$_.Reason -eq "Host is entering maintenance mode"} | Apply-DrsRecommendation

Get the task output object and save it as a variable.

$myUpdatedHost = Wait-Task $updateHostTask