VMware Cloud Community
ehsanijavad
Enthusiast
Enthusiast
Jump to solution

Get-DrsRule does not work

Hi all

Maybe someone know why this command does not work.

$CLS = Get-Cluster XXX
Get-DrsRule -Cluster $CLS

Thanks in advance for your help.

0 Kudos
2 Solutions

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If you want to use the vSphere objects instead of the .NET objects, that is your choice.

Isn't using the Type parameter exactly what I have been telling you.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
ehsanijavad
Enthusiast
Enthusiast
Jump to solution

0 Kudos
19 Replies
LucD
Leadership
Leadership
Jump to solution

When there are no DRS rules in that cluster, the cmdlet doesn't return anything


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ehsanijavad
Enthusiast
Enthusiast
Jump to solution

Hi LucD

 

Thanks for your message.

There are some rules on cluster.

These commands return the rules.


foreach($vm in Get-VM -Location $CLS){

Get-DrsRule -Cluster $CLS -VM $vm -Type VMHostAffinity
}

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Only the Cluster parameter is a required parameter.
Just tested that and it works for me.
Which PowerCLI and vSphere version are you using?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ehsanijavad
Enthusiast
Enthusiast
Jump to solution

Hi LucD

ehsanijavad_0-1626265440721.png

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is not the latest version, but should be ok.

So the following is not returning anything for you?

Get-DrsRule -Cluster cluster


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ehsanijavad
Enthusiast
Enthusiast
Jump to solution

it does not work for me.

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you perhaps trying to see VMHostAffinity rules?
Without Type or VMHost parameter you don't get those.
As the Get-DrsRule cmdlet clearly states:

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ehsanijavad
Enthusiast
Enthusiast
Jump to solution

I want to return all type of DRS rules.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is not what I asked.

If you RTFM, you will see that you have to use the Type or VMHost parameter to retrieve the VMHostAffinityRules.
If you do not use those parameters, the cmdlet will only return VMAffinity and VMAntiAffinity rules.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ehsanijavad
Enthusiast
Enthusiast
Jump to solution

what do you think about this one:

$CLS.ExtensionData.ConfigurationEx.Rule

or

Get-DrsRule -Cluster $CLS -Type VMHostAffinity,VMAntiAffinity,VMAffinity

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you want to use the vSphere objects instead of the .NET objects, that is your choice.

Isn't using the Type parameter exactly what I have been telling you.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ehsanijavad
Enthusiast
Enthusiast
Jump to solution

Thanks LucD.

0 Kudos
inglucortesgi
Contributor
Contributor
Jump to solution

Hi LucD, 

I'm trying to run Get-DrsRule cmdlet, but the results not showing the VMID's (these rules are correctly configured through GUI)

PS C:\> Get-Drsrule -cluster "NAMED2" -Type VMHostAffinity

Name                         Enabled  Type             VMIDs
----                         -------  ----             -----
VMs must be in SiteA         True     VMHostAffinity
VMs must be in SiteB         True     VMHostAffinity
VMs should in SiteA          True     VMHostAffinity
VMs should in SiteB          True     VMHostAffinity
MYM VMs should be in SiteB   True     VMHostAffinity

I've tried create new rules through New-DrsClusterGroup cmdlet like this:

New-DrsClusterGroup -Name "Hosts-TEST" -Cluster "NAMED3" -VMHost vnamed1a.local,vnamed3a.local

And I can see this rules through GUI, but get-drsclustergroup cmdlet not shows any results... 

PS C:\> Get-DrsClusterGroup
PS C:\>

I need to get the list of the VMs in each VM Host rules.

I would really appreciate your help, thanks

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Check what the cluster configuration says about the groups and rules

$clusterName = 'NAMED2'

$cluster = Get-Cluster -Name $clusterName

$cluster.ExtensionData.ConfigurationEx.Group
$cluster.ExtensionData.ConfigurationEx.Rule


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
inglucortesgi
Contributor
Contributor
Jump to solution

I put the results on the attachment... no data on VMgroup or VMHostgroup columns.

vCenter Server: Version:7.0.3 Build: 19717403
Hypervisor: VMware ESXi, 7.0.3, 19193900

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That seems to indicate there are no VM or VMHost groups defined for that cluster.
Strange that you seen them in the Web Client


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Tags (1)
0 Kudos
inglucortesgi
Contributor
Contributor
Jump to solution

Yep, actually the configuration VM/Host Groups and VM/Host Rules works properly. I attached some images about our environment (please suppose that red square reference to SiteA).

It could be a bug associated to PowerCli? or vCenter version? What do you think?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

In the previous snippet we used the vSphere API directly (ExtensionData), so most probably has nothing to do with PowerCLI.
There could be an issue in vSphere.
I suggest opening an SR.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
inglucortesgi
Contributor
Contributor
Jump to solution

Hi LucD, we've just upgrade PowerCLI to the last version and both commands now works properly. Thanks fou your help.

0 Kudos