You can create a VM-VMHost DRS rule within a cluster after creating a VM DRS cluster group and a VMHost DRS cluster group.
Prerequisites
- Verify that you are connected to a vCenter Server system.
- Verify that virtual machines and hosts exist within a cluster with enabled DRS in the vCenter Server environment.
Procedure
- Get the virtual machines for the VM DRS cluster group.
$vms = Get-VM "VM1", "VM2"
- Get the hosts for the VMHost DRS cluster group.
$vmHosts = Get-VMHost "hostname1", "hostname2"
- Get the cluster where you want to create the rule.
$cluster = Get-Cluster "MyCluster"
- Create a VM DRS cluster group.
$vmGroup = New-DrsClusterGroup -Name "MyVmsDrsClusterGroup" -VM $vms -Cluster $cluster
- Create a VMHost DRS cluster group.
$vmHostGroup = New-DrsClusterGroup -Name "MyVmHostsDrsClusterGroup" -VMHost $vmHosts -Cluster $cluster
- Create the VM-VMHost DRS rule by using the newly created VM DRS cluster group and VMHost DRS cluster group.
New-DrsVMHostRule -Name "MyDrsRule" -Cluster $cluster -VMGroup $vmGroup -VMHostGroup $vmHostGroup -Type "MustRunOn"