Export (0) Print
Expand All

MaintenanceModeInCluster.ps1

Updated: August 14, 2009

Applies To: Virtual Machine Manager 2008 R2, Virtual Machine Manager 2008 R2 SP1

In System Center Virtual Machine Manager (VMM) 2008 R2, you can start maintenance mode for a Windows-based host anytime you need to perform maintenance tasks (such as applying updates or replacing a physical component) on the host.

When you use the Disable-VMHost cmdlet to place a Windows Server 2008 R2 clustered host into maintenance mode, you can choose one of the following methods:

  • Use the MoveWithinCluster parameter to evacuate all running highly available virtual machines to other hosts on the same cluster using live migration. Virtual machines that are not highly available are placed into a saved state.

  • Place all running virtual machines on the host into a saved state.

While in maintenance mode, VMM automatically does the following:

  • It blocks virtual machine creation operations on the host.

  • It excludes the host from the host ratings during placement.

  • It sets the value for the host state property to In Maintenance Mode.

After you complete maintenance activities on the host, use the Enable-VMHost cmdlet to remove the host from maintenance mode and to place it back in service. When the host is placed back in service, VMM does the following:

  • It allows virtual machine creation on the host.

  • It includes the host in the host rating calculations during placement.

  • It sets the value for the host state property back to the host's current state.

However, VMM does not automatically move highly available virtual machines back onto the host, and it does not restart any of the virtual machines that were placed in a saved state.

The following script gets all the VMM hosts in a cluster, sequentially places each host into maintenance mode using the MoveWithinCluster parameter, pauses for maintenance activities, and then restarts the host.

Disclaimer


# Filename:      MaintenanceModeInCluster.ps1
# Description:   Sequentially places each host in a cluster into maintenance mode.
#                The MoveWithinCluster parameter indicates that all running highly 
#                available virtual machines are moved to other hosts in the cluster 
#                using live migration. Virtual machines that are not highly available 
#                are placed into a saved state. The script pauses for maintenance 
#                activities and then places the host back into service.

# Connect to the VMM server.
$VMMServer = Get-VMMServer -ComputerName "VMMServer01.Contoso.com"

# Get the hosts in the cluster.
$Cluster = Get-VMHostcluster -Name "Cluster01"
$VMHosts = Get-VMHost -VMHostCluster $Cluster

# Sequentially place each host in the cluster into maintenance mode, 
# pause the script for maintenance activities, and then place 
# the host back into service.

Foreach ($VMHost in $VMHosts)
{
   Write-Host "Placing host" $VMHost "into maintenance mode."
   Disable-VMHost $VMHost -MoveWithinCluster
   Start-Sleep "60"
   Write-Host "Placing host" $VMHost "back into service."
   Enable-VMHost $VMHost
}

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft