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.

1

Save the Host host object as a variable.

$host = Get-VMHost -Name Host
2

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

$hostCluster = Get-Cluster -VMHost $host
3

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
Note

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.

4

Get and apply the recommendations generated by DRS.

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

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

$myUpdatedHost = Wait-Task $updateHostTask