Need help to get the List of VM – Hosts which are part of affinity rules using Power cli ?
Which type of rules do you want, inter-VM affinity or VM-VMHost affinity?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
We have vSphere Cluster configured in stretch so DR side & Prod side ESXi host configured in Single vSphere Cluster. However, to avoid VM failover / Power On from PROD host to DR host or vice versa we have defined Affinity Rule in Single Cluster.
So here I am looking three column output
Are there then only 2 such rules on the cluster?
If yes, then the script could be quite simple.
Something like this for example
$cluster = Get-Cluster -Name $clusterName
$vmInRule = @()
Get-DrsVMToVMHostRule -Cluster $cluster |
ForEach-Object -Process {
$vm = (Get-DrsClusterGroup -Cluster $cluster -Name $_.VmGroupName).Member.Name
$vmInRule += $vm
$obj = [ordered]@{
RuleName = $_.Name
VM = $vm -join '|'
}
New-Object psobject -Property $obj
}
$obj = [ordered]@{
RuleName = 'Not in a rule'
VM = (Get-VM -Location $cluster | where {$vmInRule -notcontains $_.Name}).Name -join '|'
}
New-Object psobject -Property $obj
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference