Activate Maintenance Mode for a Host on vCenter Server

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.

Prerequisites

Verify that you are connected to a vCenter Server system.

Procedure

  1. Save the Host host object as a variable.
    $vmhost = Get-VMHost -Name Host
  2. Get the cluster to which Host belongs and save the cluster object as a variable.
    $vmhostCluster = Get-Cluster -VMHost $vmhost
  3. 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
    Note: 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.
  4. Get and apply the recommendations generated by DRS.
    Get-DrsRecommendation -Cluster $vmhostCluster | where {$_.Reason -eq "Host is entering maintenance mode"} | Invoke-DrsRecommendation
  5. Get the task output object and save it as a variable.
    $myUpdatedHost = Wait-Task $updateHostTask