Get-DrsRule
This cmdlet retrieves the list of DRS rules for the specified clusters. Each rule defines the virtual machines that can run on the same host (affinity rule) or must run on different hosts (anti-affinity).Note: To retrieve VMHostAffinity rules, you need to state this explicitly by using the Type or the VMHost parameter. Otherwise, this cmdlet returns VMAffinity and VMAntiAffinity rules.
Syntax
Parameters
Required | Parameter Name | Type | Position | Features | Description |
---|---|---|---|---|---|
required
|
Cluster | Cluster[] | 1 |
|
Specifies the clusters for which you want to retrieve the DRS rules. |
optional | VM | VirtualMachine[] | 2 |
|
Specifies virtual machines to filter the DRS rules that reference them. Passing values to this parameter through a pipeline is deprecated and will be removed in a future release. |
optional | Name | String[] | named |
|
Specifies the name of the DRS rule you want to retrieve. |
optional | ProgressAction | ActionPreference | named |
|
|
optional | Server | VIServer[] | named |
|
Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of Connect-VIServer. |
optional | Type | ResourceSchedulingRuleType[] | named |
|
Specifies the type of DRS rules you want to retrieve. This parameter accepts VMAntiAffinity, VMAffinity, and VMHostAffinity values. You cannot set this parameter, when the VMHost parameter is specified. |
Parameters
Required | Parameter Name | Type | Position | Features | Description |
---|---|---|---|---|---|
required
|
Cluster | Cluster[] | 1 |
|
Specifies the clusters for which you want to retrieve the DRS rules. |
optional | VM | VirtualMachine[] | 2 |
|
Specifies virtual machines to filter the DRS rules that reference them. Passing values to this parameter through a pipeline is deprecated and will be removed in a future release. |
optional | Name | String[] | named |
|
Specifies the name of the DRS rule you want to retrieve. |
optional | ProgressAction | ActionPreference | named |
|
|
optional | Server | VIServer[] | named |
|
Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of Connect-VIServer. |
optional | VMHost | VMHost[] | named |
|
Specifies VM hosts to filter the DRS rules that reference them. When this parameter is specified, the cmdlet returns only VMHostAffinity rules. You cannot set this parameter, when the Type parameter is specified. |
Output
VMware.VimAutomation.ViCore.Types.V1.Cluster.DrsRuleExamples
Example 1
$myCluster = Get-Cluster -Name "MyCluster1" Get-DrsRule -Cluster $myCluster -Name "*Rule1*"
Retrieves the DRS rules for the cluster stored in the $myCluster variable, whose names contain "Rule1".
Example 2
Get-Cluster -Name 'MyCluster1' | Get-DrsRule
Retrieves the virtual machine affinity and anti-affinity rules for the specified cluster by pipeline.
Example 3
$myVm1 = Get-VM -Name 'MyVm1' $myCluster1 = Get-Cluster 'MyCluster1' Get-DrsRule -Cluster $myCluster1 -VM $myVm1
Retrieves the virtual machine affinity and anti-affinity rules for the specified virtual machine in the specified cluster.
Example 4
Get-Cluster 'MyCluster1' | Get-DrsRule -Type VMHostAffinity
Retrieves virtual machine to host affinity rules for the specified cluster by pipeline.
Example 5
$myVMHost1 = Get-VMHost -Name 'MyVMHost1' $myCluster1 = Get-Cluster -Name 'MyCluster1' Get-DrsRule -Cluster $myCluster1 -VMHost $myVMHost1
Retrieves virtual machine to host affinity rules for the specified host and cluster.
Related Commands
DrsClusterGroup
This cmdlet retrieves DRS cluster groups for the specified cluster, VM, or VM host.
This cmdlet creates either a VM or VM host DRS cluster group, depending on the used parameter set.
This cmdlet removes the specified DRS cluster groups from the cluster on which it resides.
This cmdlet adds or removes either virtual machines or VM hosts to or from the specified DRS cluster group, depending on the used parameter set.
DrsRecommendation
This cmdlet retrieves the available DRS recommendations from the provided clusters.
This cmdlet applies the specified DRS recommendations.
DrsRule
This cmdlet retrieves the list of DRS rules for the specified clusters.
This cmdlet creates a new DRS rule.
This cmdlet removes the specified DRS rules.
This cmdlet modifies an existing DRS rule.
DrsVMHostRule
This cmdlet retrieves VM to VMHost DRS rules that match the specified filters.
This cmdlet creates a new VM to VMHost DRS rule.
This cmdlet removes the specified VM to VMHost DRS rule.
This cmdlet modifies the specified VM to VMHost DRS rule.