I was in need of a way to check if a VM is placed in 2 DRS groups so i made a little script to read out the vm cluster groups and get the members (vm’s) and then output the names of the vm’s that are in both groups. This bit of code also includes a little bit fancier way to connect to a vcenter for readout.
#Connect to vCenter
Try {
if ($Connect) {
Continue
}
else {
$Credential = Get-Credential -Message "Provide username and password."
$vcenter = Read-Host "Enter vCenter Name..."
$connect = Connect-VIServer $vcenter -Credential $Credential
Write-Host Connected to $connect -ForegroundColor Green
}
}
Catch {
$Error
}
#Get VM's currently in DRS VM Groups
$D1VMs = (Get-DrsClusterGroup -Name "VM-D1" | Select-Object Member -ExpandProperty Member)
$D2VMs = (Get-DrsClusterGroup -Name "VM-D2" | Select-Object Member -ExpandProperty Member)
$Compare = Compare-Object -ReferenceObject $D1VMs -DifferenceObject $D2VMs -Property Name -IncludeEqual
$Compare
Disconnect-VIServer
you can ofcourse then export this list with export-csv or out-file, or take the script further and take action to remove the vm from 1 of the 2 groups, small example :
Get-DrsClusterGroup -Name "VM-D1" | Set-DrsClusterGroup -VM "PD-TEST04" -Remove
instead of hardcoding take the output of the compare script :).
The original article was posted on: www.hollebollevsan.nl