Each one of the vSphere clusters that I manage have an identical set of guests. I wrote this script as a handy way of setting/correcting any HA restart priorities per documented standards.
[powershell]
Connect-VIServer vcenter.domain.com -Protocol https
$location = Read-Host "Please enter location or top level folder:"
$location = $location.ToUpper()
if ($location.Contains("LocationX")){
Write-Output "This script is not intended for anything in the LocationX folder. Exiting…"
break
} else {
$clusters = Get-Cluster -Location $location
foreach ($cluster in $clusters){
if ($cluster.HAEnabled -ne "True"){
Set-Cluster $cluster -HAEnabled:$true -HAAdmissionControlEnabled:$true -HAFailoverLevel "1" -Confirm:$false
}
}
$vm_high = Get-VM -Location $location | where {$_.Name -like "HighPriorityServer*"}
foreach ($vm in $vm_high) {
if ($vm.HARestartPriority -ne "High") {
Set-VM $vm -HARestartPriority "High" -RunAsync:$true -Confirm:$false
}
}
$vm_med = Get-VM -Location $location | where {$_.Name -like "MediumPriorityServer*"}
foreach ($vm in $vm_med) {
if ($vm.HARestartPriority -ne "Medium") {
Set-VM $vm -HARestartPriority "Medium" -RunAsync:$true -Confirm:$false
}
}
}
[/powershell]
As usual, the names of the servers have been changed to protect the innocent. 🙂 Since this script was written for anyone on our VMware team to use, I added the “LocationX” conditional; that is, I didn’t want this script ran on a particular location/datacenter.
[…] One of the unique but potentially frustrating things about the environment that I support is that many of the clusters & guests are setup the same exact way at multiple locations. PowerCLI has really helped reduce the amount of time it takes to verify settings, and to set them correctly (although, that’s another post). […]