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

Verify that you are connected to a vCenter Server system.


Save the Host host object as a variable.

$vmhost = Get-VMHost -Name Host

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

$vmhostCluster = Get-Cluster -VMHost $vmhost

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

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

If the host is not automated or is partially automated and has powered-on virtual machines running on it, you must use 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 $vmhostCluster | where {$_.Reason -eq "Host is entering maintenance mode"} | Invoke-DrsRecommendation

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

$myUpdatedHost = Wait-Task $updateHostTask