If you want to shut down, patch, upgrade, or reconfigure a host, you do not want any virtual machines running on the host. If you put a host in maintenance mode, you are sure that no virtual machines will be moved to or started on the host. If the host is running on a fully automated DRS-enabled cluster, the DRS will move the running virtual machines from the host to other hosts in the cluster using vMotion.
The following screenshot of the vSphere Web Client shows the different DRS automation levels that a cluster can have:
To put a host in maintenance mode, you have to use the Set-VMHost
cmdlet.
This cmdlet has the following syntax:
Set-VMHost [-VMHost] <VMHost[]> [[-State] <VMHostState>] [-VMSwapfilePolicy <VMSwapfilePolicy>] [-VMSwapfileDatastore <Datastore>] [-Profile <VMHostProfile>] [-Evacuate] [-TimeZone <VMHostTimeZone>] [-LicenseKey <String>] [-VsanDataMigrationMode <VsanDataMigrationMode>] [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]
The -VMHost
parameter is required.
To put a host in maintenance mode, you have to set the state to Maintenance
. To disable maintenance mode, you have to set the state to Connected
. The Set-VMHost -State
parameter has a third possible value, which is Disconnected
. You can use Disconnected
to disconnect a host from the vCenter Server.
So, let's put the host in maintenance mode first:
PowerCLI C:> $VMHost = Get-VMHost -Name 192.168.0.133 PowerCLI C:> $VMHost | Set-VMHost -State Maintenance Name ConnectionState PowerState NumCpu CpuUsageMhz ---- --------------- ---------- ------ ----------- 192.168.0.133 Maintenance PoweredOn 2 47
To disable maintenance mode, you have to use the following command:
PowerCLI C:> $VMHost | Set-VMHost -State Connected Name ConnectionState PowerState NumCpu CpuUsageMhz ---- --------------- ---------- ------ ----------- 192.168.0.133 Connected PoweredOn 2 139
18.189.2.122