VMware Cloud Community
Chakoe1
Contributor
Contributor
Jump to solution

Get-Cluster <cluster> | Get-DRS-Rules not showing existing Rules

Hi all,

if i use

Get-Cluster Cluster10 | Get-DRS-Rule

PowerCLI returns nothing.

If i use $test2 = Get-View (Get-Cluster Cluster10 ) and then $test.Configuration.Rule  , it shows me the following:

VMGroupName :                   VM-Group1

AffineHostGroupName          Cluster10-HostGroup1

AntiAffineHostGroupName:

Key:                                        8

Status

Enabled                                  True

Name:                                   Cluster10-Rule1

Mandatory:                            false

UserCreated                         True

InCompliance    

RuleUuid                              5207b877-be94-0d3a-57b1-4e902d8eed9f

Questions:

1) why do i get no results with Example 1 ?

2) Is ist possible to build a report with the following infos:

VM-Name                    <- easy

ClusterName               <- easy

Rules for the VM

Type of rule

Background:

We have Cluster10. Cluster10 has 20 ESX-Hosts. 10 Hosts on Site1 , 10 Hosts on Site2. Then we have an ESX-Group for each Site.

Now we build a VM-Group for DomainControllers for each Site. Now we build a rule to map the DomainControllers for Site 1 to the ESX-Servers in Site1.

What we want is a report for this 🙂

Any ideas?

Greets

Chakoe

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You didn't use my last version, note that the Format-List is not there anymore.


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

View solution in original post

Reply
0 Kudos
14 Replies
LucD
Leadership
Leadership
Jump to solution

1) As stated in Get-DrsRule​ page, you need to use the Type or VMHost parameter to see VMHostAffinity rules.

2) Try like this

foreach($cluster in Get-Cluster){

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

        Get-DrsRule -Cluster $cluster -VM $vm |

        Select @{N='Cluster';E={$cluster.Name}},

            @{N='VM';E={$vm.Name}},

            Name,Type

    }

}


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

Reply
0 Kudos
Chakoe1
Contributor
Contributor
Jump to solution

Hi,

i changes the script , so i can see, what it´s actually doing.. Ialso i added "-Type VMhostAffinity" .  But now it reports all Vms , even if they are not affected by any DRS Rule.

Also : is ist possible to show the information, which Hosts are in the AffineHostGroup? Output shows only AffineHostIds...in other words:

How do i add this information and how do i translate the ID into the ESX-Hostname? How do i skip VMs without any Rule?

foreach($cluster in Get-Cluster){

    Write-Host "Processing" $cluster.Name "..."

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

        Write-Host "Processing" $vm "in" $cluster.Name "..."

        Get-DrsRule -Cluster $cluster -VM $vm -Type VMHostAffinity |

        Select  @{N='Cluster';E={$cluster.Name}},

                @{N='VM';E={$vm.Name}},

            Name,Type

    }

}

Reply
0 Kudos
Chakoe1
Contributor
Contributor
Jump to solution

Edit:

ok....i now i know, why it´s putting ALL VMs ...it because of my "Write-Host"...  🙂

Edit2:

changed / added some lines, now it looks like this:

foreach($cluster in Get-Cluster){

   

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

   Get-DrsRule -Cluster $cluster -VM $vm -Type VMHostAffinity |

        Select  @{N="Cluster";E={$cluster.Name}},

               @{N="VM";E={$vm.Name}},

               @{N="RuleName";E={$_.Name}},

               @{N="RuleType";E={$_.Type}},

               @{N="RuleHosts";E={$_.AffineHOstIds}} | fl

        

    }

}

Remaining Question: How do i translate the VMHOstIDs into their Hostnames and how do i export it into a Gridview ?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

foreach($cluster in Get-Cluster){

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

        Get-DrsRule -Cluster $cluster -VM $vm -Type VMHostAffinity |

        Select  @{N="Cluster";E={$cluster.Name}},

               @{N="VM";E={$vm.Name}},

               @{N="RuleName";E={$_.Name}},

               @{N="RuleType";E={$_.Type}},

               @{N="RuleHosts";E={(Get-View -Id $_.AffineHostIds).Name -join ','}} | fl

    }

}


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

Reply
0 Kudos
Chakoe1
Contributor
Contributor
Jump to solution

works fine for me 🙂 only the Gridview fails

+ }) | Out-Gridview

+      ~~~~~~~~~~~~

    + CategoryInfo          : InvalidType: (:) [Out-GridView], FormatException

    + FullyQualifiedErrorId : DataNotQualifiedForGridView,Microsoft.PowerShell.Commands.OutGridViewCommand

I think this is because of the multiple Values for the Hosts ?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, it's because a ForEach statement doesn't place anything on the pipeline.

Try like this

$report = foreach($cluster in Get-Cluster){

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

        Get-DrsRule -Cluster $cluster -VM $vm -Type VMHostAffinity |

        Select  @{N="Cluster";E={$cluster.Name}},

               @{N="VM";E={$vm.Name}},

               @{N="RuleName";E={$_.Name}},

               @{N="RuleType";E={$_.Type}},

               @{N="RuleHosts";E={(Get-View -Id $_.AffineHostIds).Name -join ','}}

    }

}

$report | Out-GridView


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

Reply
0 Kudos
Chakoe1
Contributor
Contributor
Jump to solution

Hi Luc,

sorry.. but this is not working 😞

Script:

$report = foreach($cluster in Get-Cluster){

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

        Get-DrsRule -Cluster $cluster -VM $vm -Type VMHostAffinity |

        Select  @{N="Cluster";E={$cluster.Name}},

               @{N="VM";E={$vm.Name}},

               @{N="RuleName";E={$_.Name}},

               @{N="RuleType";E={$_.Type}},

               @{N="RuleHosts";E={(Get-View -Id $_.AffineHostIds).Name -join ','}} | fl

    }

}

$report | Out-Gridview

Error Message:

+ $report | Out-Gridview

+           ~~~~~~~~~~~~

    + CategoryInfo          : InvalidType: (:) [Out-GridView], FormatException

    + FullyQualifiedErrorId : DataNotQualifiedForGridView,Microsoft.PowerShell.Commands.OutGridViewCommand

Reply
0 Kudos
Chakoe1
Contributor
Contributor
Jump to solution

Got it...

Cause was   " ..... | fl "

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You didn't use my last version, note that the Format-List is not there anymore.


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

Reply
0 Kudos
Chakoe1
Contributor
Contributor
Jump to solution

Yes, you were right 🙂

Works fine for me now...

Reply
0 Kudos
LeMaster
Contributor
Contributor
Jump to solution

I have been using this since it was posted and love the information and output and the format that the report comes in.  I recently noticed that I get a warning saying that the command is obsolete and that Get-DrsRule needs to be replaced with Get-DrsVMHostRule.  This is not just an inplace swap of the command as the options do not copy over to the new command.  I have seen output from the new command (running scripts off of the http://www.cloudyfuture.net/2017/08/02/document-drs-rules-powercli/ site), but I do not get the level of detail from this new commandlet from what I have been able to see.

Has anyone successfully swapped from the Get-DrsRule to the Get-DrsVMHostRule and maintained the same level of detail in the output?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which details are you missing?


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

Reply
0 Kudos
LeMaster
Contributor
Contributor
Jump to solution

I am sorry for the delayed response, I was having issues with the site.

Cluster    VM      Enabled RuleName                     RuleType   Mandatory RuleHosts             
-------    --      ------- --------                     --------   --------- ---------             
Cluster01    VM21    True     Rule.1 (Same Host)          VMAffinity False                       
Cluster01    VM22    True     Rule.1 (Same Host)          VMAffinity False                       
Cluster01    VM29    True     Rule.1 (Same Host)          VMAffinity False                       
Cluster01    VCSA01  True     vCenter                   VMHostAffinityFalse    esxi01
Cluster03    VCSA03  True     vCenter                   VMHostAffinityFalse    esxi03
Cluster02    VCSA02  True     vCenter                   VMHostAffinityFalse  esxi02
Cluster04    NSX2   True     NSX Controllers Anti-Affinity    VMAntiAffinityFalse                       
Cluster04    NSX3   True     NSX Controllers Anti-Affinity    VMAntiAffinityFalse                       
Cluster04    DLR00   True     DLR Anti-Affinity         VMAntiAffinityFalse                       
Cluster04    DLR01   True     DLR Anti-Affinity         VMAntiAffinityFalse                       
Cluster04    ESG00   True     ESG Anti-Affinity         VMAntiAffinityFalse                       
Cluster05    vCenter True     vCenter Pin to Esxi01     VMHostAffinityFalse    esxi05
Cluster05    DLR10   True     anti-affinity-rule-edge-5 VMAntiAffinityFalse                       
Cluster05    DLR11   True     anti-affinity-rule-edge-5 VMAntiAffinityFalse                       
Cluster05    ESG10   True     anti-affinity-rule-edge-4 VMAntiAffinityFalse                       
Cluster05    ESG11   True     anti-affinity-rule-edge-4 VMAntiAffinityFalse                       

PS> $drsreport = foreach($cluster in Get-Cluster|sort){Get-DrsRule -Cluster $cluster | Select Name, Enabled, Type, @{Name="VM"; Expression={ $iTemp = @(); $_.VMIds | % { $iTemp += (Get-VM -Id $_).Name }; [string]::Join(";", $iTemp) }}};$drsreport | Format-Table

Name                          Enabled            Type VM                                                        

----                          -------            ---- --                                                        

Rule.1 (Same Host)             True         VMAffinity VM29;VM01;VM21;VM22   

NSX Controllers Anti-Affinity  True     VMAntiAffinity NSX2;NSX3

ESG Anti-Affinity              True     VMAntiAffinity ESG00                                              

DLR Anti-Affinity              True     VMAntiAffinity DLR00;DLR01                                 

anti-affinity-rule-edge-4      True     VMAntiAffinity ESG10;ESG11;VMTest     

anti-affinity-rule-edge-5      True     VMAntiAffinity DLR10;DLR11                                 

PS> $drsreport = foreach($cluster in Get-Cluster|sort){Get-DrsClusterGroup -Cluster $cluster | select Name, Cluster, GroupType, @{Name="Member:"; Expression={[string]::Join(";", $_.Member)}}};$drsreport | Format-Table

Name          Cluster       GroupType         Member:                    

----          -------       ---------         -------                    

vCenter       Cluster01     VMGroup         VCSA01              

esxi01          Cluster01     VMHostGroup     esxi01

Rule.6        Cluster01     VMGroup         VM05              

esxi16           Cluster01     VMHostGroup     esxi16

esxi15           Cluster01     VMHostGroup                            

vCenter       Cluster03     VMGroup         VCSA03              

esxi03           Cluster03     VMHostGroup     esxi03

vCenter       Cluster02     VMGroup         VCSA02              

esxi02           Cluster02     VMHostGroup     esxi02

vCenter       Cluster04     VMGroup                            

ESXi01        Cluster04     VMHostGroup                            

vCenter       Cluster05     VMGroup         Cluster05 vCenter          

Host01        Cluster05     VMHostGroup     esxi05

I like seeing the information per VM, like your script does, and the new command groups the VMs together.  Additionally, I am seeing different responses (in your script, it shows 3 VMs that run Rule.1 where the new way do get the information "get-drsrule" shows 4 VMs).

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you mean something like this?

Get-Cluster -PipelineVariable cluster |

Get-DrsVMHostRule -PipelineVariable rule  |

ForEach-Object -Process {

    (Get-DrsClusterGroup -Name $rule.VMGroup -Type VMGroup -Cluster $cluster).Member |

    Select @{N='Cluster';E={$cluster.Name}},

        @{N='VM';E={$_.Name}},

        @{N='RuleName';E={$rule.Name}},

        @{N='RuleType';E={

            if($_.Type -match "Not"){

                'VMhostAntiAffinity'

            }

            else{

                'VMHostAffinity'

            }

        }},

        @{N='RuleHosts';E={

            (Get-DrsClusterGroup -Name $rule.VMHostGroup).Member.Name -join ','

        }}

}


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

Reply
0 Kudos