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).
This time around, I wanted to be able to check what the HA & EVC settings were for all clusters in a folder. I also wanted to use that same script to check the guest VM HA restart priorities (domain controllers first, DHCP second, etc.). Here’s what I came up with, I hope someone finds it to be useful!
[powershell]
function cluster_report($location) {
$clusters = Get-Cluster -Location $location
$cdetails = @()
foreach ($cluster in $clusters) {
$cdetail = "" | select Cluster,HAEnabled,EVCMode
$cdetail.Cluster = $cluster.Name
$cdetail.HAEnabled = $cluster.HAEnabled
$cdetail.EVCMode = $cluster.ExtensionData.Summary.CurrentEVCModeKey
$cdetails += $cdetail
}
return $cdetails
}
function guest_report($location){
$guests = Get-VM -Location $location
$gdetails = @()
foreach ($guest in $guests){
$gdetail = "" | select Cluster,Name,HARestartPriority
$gdetail.Cluster = $guest.Host.Parent.Name
$gdetail.Name = $guest.Name
$gdetail.HARestartPriority = $guest.HARestartPriority
$gdetails += $gdetail
}
return $gdetails
}
Write-Host
Write-Host "Please select the report settings:"
Write-Host "1: Cluster HA & EVC settings based on location"
Write-Host "2: VM guest HA restart priorities based on location"
$setting = Read-Host
$location = Read-Host "Please enter the location or cluster name"
$location = $location.ToUpper()
$viserver = Connect-VIServer vcenter.domain.com -Protocol https
switch($setting) {
1 {cluster_report($location) | ft}
2 {guest_report($location) | Sort Name}
default {break}
}
[/powershell]