13 Replies Latest reply on Jan 17, 2017 6:55 AM by TWGarland

    Managind DRS Groups via powercli

    SubnetJO Novice

      Goodmorning.

      I need to get all the members of a Virtual machine DRS Group via PowerCli.

      I found some articles aroud with cmdlets such as "New-DrsVmGroup" or so on.

       

      I cannot see any of that cmdlets in my powercli.

      I connect to a 5.0 Virtual Center that manages 6 ESXi 4.1 hosts.

       

      Using PowerCli 5.1 release 1 from my Windows8 laptop or PowerCli 5.0.1 from the Virtual Center Server itself I can see the following:

       

       

      PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> get-help *drs* | ft name

       

      Name
      ----
      Apply-DrsRecommendation
      Get-DrsRecommendation
      Get-DrsRule
      New-DrsRule
      Remove-DrsRule
      Set-DrsRule

       

       

       

      Could you please help me to get on the right way to manage DRS groups from powercli?

       

      Many thanks for youe help.

        • 1. Re: Managind DRS Groups via powercli
          Jon Munday Master
          vExpert

          This is not a native cmdlet, but a custom function written by Arnim van Lieshout.

           

          See his article below;

          http://www.van-lieshout.com/2011/06/drs-rules/

           

           

          These are the native cmdlets;


          Name                         Category  Synopsis
          ----                         --------  --------
          Apply-DrsRecommendation      Cmdlet    Applies the specified DRS recommendations.
          Get-DrsRecommendation        Cmdlet    Retrieves the available DRS recommendations from the provided clusters.
          Get-DrsRule                  Cmdlet    Retrieves the list of DRS rules for the specified clusters.
          New-DrsRule                  Cmdlet    Creates a new DRS rule.
          Remove-DrsRule               Cmdlet    Removes the specified DRS rules.
          Set-DrsRule                  Cmdlet    Modifies an existing DRS rule.

           

           

           

          Message was edited by: jrmunday

          • 2. Re: Managind DRS Groups via powercli
            Grzesiekk Expert

            I think that you are thinking about those functions

             

            http://www.van-lieshout.com/2011/06/drs-rules/

             

            They are perfect, i was using them for some time now.

            • 3. Re: Managind DRS Groups via powercli
              SubnetJO Novice

              have read the article but unfortunately the VMIDs of the VMs that are member of the VM DRS group are not listed, in my case.

              This cannot be a solution for me.

              I have seen another question for a script to list the member of a DRS group in the comments, but with no luck.

               

              I need to know the members of a couple of VM DRS groups, if there is no solution via powercli, I wiil have to manually create mantein an off-line list of both :-(

               

              Thank you for your support.

              • 4. Re: Managind DRS Groups via powercli
                Grzesiekk Expert

                Hi

                  i wrote quickly 1 liner for you:

                 

                (get-cluster cluster_name).ExtensionData.ConfigurationEx.group|?{$_.vm}|%{" GROUP $($_.name) found in this cluster"; foreach($currentvm in $_.vm) { (get-view -id $currentvm).name } }
                GROUP VmGroup1 found in this cluster

                vmX

                vmY

                vmZ

                GROUP VmGroup2 found in this cluster
                vmA

                vmB

                vmC

                vmD

                 

                Let me know if you have still questions regarding this

                • 5. Re: Managind DRS Groups via powercli
                  MKguy Virtuoso

                  Can you use the Get-DrsGroup function provided here? http://communities.vmware.com/message/1699823#1699823

                   

                  It lists VM and host DRS groups with all VMs assigned to them.

                  1 person found this helpful
                  • 6. Re: Managind DRS Groups via powercli
                    SubnetJO Novice

                    Thank you very much.

                     

                    It worked great!

                    • 7. Re: Managind DRS Groups via powercli
                      SubnetJO Novice

                      That function is great!

                      I marked the Grzesiekk answer as correct so I could mark your as "useful".

                       

                      Both solutions are great for my scripting purposes.

                       

                      Really thank you for your kind support

                       

                      Regards

                      • 8. Re: Managind DRS Groups via powercli
                        Grzesiekk Expert

                        I wasn't even aware that Robert wrote that one. It's really nice one.

                        Anyways, im glad that you can proceed now with your script !

                        Greg

                        • 9. Re: Managind DRS Groups via powercli
                          aenagy Hot Shot

                          If I try the following I don't get any output. (PowerShell 2, vCenter & ESXi 5.1, PowerCLI 5.1 Release 1)


                          (get-cluster ).ExtensionData.ConfigurationEx.group|?{$_.vm}

                          or

                          (get-cluster ).ExtensionData.ConfigurationEx.group

                           

                          I know I have a DRS rule because when I try the following I am able to see it in the object browser in PowerGUI and I just created it in Web Client.

                           

                          $Clusters = Get-Cluster

                          • 10. Re: Managind DRS Groups via powercli
                            kunaludapi Expert
                            vExpert

                            $groups = ((get-cluster).ExtensionData.ConfigurationEx.group) | foreach {$_ | where-object {$_.gettype().name -eq "ClusterVmGroup"}}

                            foreach ($group in $groups) {

                                 $props = @{'Groupname'=$group.Name; 

                                               'Vm'= $group.vm | foreach {get-vm -id $_ }

                                            }

                                    $obj = New-Object -TypeName PSObject -Property $Props

                                    $obj

                            }

                            • 11. Re: Managind DRS Groups via powercli
                              Shaw_Way Novice

                              This gets the entire list and writes it to a time and date stamped text file. Fairly basic but gives you the idea. I just wanted a list if everything went pear shaped.

                               

                              $cr = "`r`n"
                              $tab = "`t"

                              $daytime = Get-Date -format dd_MM_yyyy_hh_mm
                              Write-Host $daytime
                              $Filename = "<path>\DRS Rules_" + "_" + $daytime + ".txt"
                              Write-Host $Filename

                              Write-Host "..Connecting to Server"
                              connect-viserver -Server <vCenter Server>

                              $ClusterList = Get-Cluster | Sort Name

                              foreach ($cluster in $ClusterList) {

                              $clusterName = $cluster.Name

                              $rules = get-cluster -Name $clusterName | Get-DrsRule -Type VMAntiAffinity

                              foreach($rule in $rules){
                                $line = ("Cluster: " + $clusterName + $cr)
                                $line += ("Rule: " + $rule.Name + " - AntiAffinity" + $cr)
                                Write-Host ("Cluster: " + $clusterName)
                                Write-Host ("Rule: " + $rule.Name + " - AntiAffinity")
                                foreach($vmId in $rule.VMIds){
                                 $line += ($tab + (Get-View -Id $vmId).Name + $cr)
                                }
                                $line | Out-File -Append $Filename
                                Write-Host $cr
                              }

                              $rules = get-cluster -Name $clusterName | Get-DrsRule -Type VMAffinity

                              foreach($rule in $rules){
                                $line = ("Cluster: " + $clusterName + $cr)
                                $line += ("Rule: " + $rule.Name + " - Affinity" + $cr)
                                Write-Host ("Cluster: " + $clusterName)
                                Write-Host ("Rule: " + $rule.Name + " - AntiAffinity" + $cr)
                                foreach($vmId in $rule.VMIds){
                                 $line += ($tab + (Get-View -Id $vmId).Name + $cr)
                                }
                                $line | Out-File -Append $Filename
                                Write-Host $cr
                              }

                              $clusterView = get-cluster -Name $clusterName | Get-View
                              $clusterConfig = $clusterView.Configuration
                              $clusterConfigEx = $clusterView.ConfigurationEx
                              $clusterConfigExGroup = $clusterConfigEx.Group
                              $rules = $clusterConfigEx.Rule

                              foreach($rule in $rules){
                                if ($rule -is [VMware.Vim.ClusterVmHostRuleInfo]) {
                                 $line = $cr
                                 $line = ("Cluster: " + $clusterName + $cr)
                                 Write-Host ("Cluster: " + $clusterName)
                                 Write-Host ("Rule: " + $rule.Name + " - AntiAffinity")
                                 $line += ("Rule: " + $rule.Name + $cr)
                                
                                 if ($rule.Mandatory) {
                                  $temp = "Must "
                                 } else {
                                   $temp = "Should "
                                 }
                                 if ($rule.AffineHostGroupName -ne $null) {
                                  $hostGroupName = $rule.AffineHostGroupName
                                  Write-Host ("Policy: " + $temp + "run on hosts in group.")
                                  $line += ("Policy: " + $temp + "run on hosts in group." + $cr)
                                 } else {
                                  $hostGroupName = $rule.AntiAffineHostGroupName
                                  Write-Host ("Policy: " + $temp + "not run on hosts in group.")
                                  $line += ("Policy: " + $temp + "not run on hosts in group." + $cr)
                                 }     
                                
                                 $vmGroupName = $rule.VmGroupName
                                 Write-Host ("VM Group: " + $vmGroupName)
                                 $line += ("VM Group: " + $vmGroupName + $cr)  
                                 $vmGroupMembers =  (Get-View -Property Name -Id ($clusterConfigExGroup | ?{($_ -is [VMware.Vim.ClusterVmGroup]) -and ($_.Name -eq $vmGroupName)}).Vm | %{$_.Name}) -join ($cr + $tab)
                                 $line += ($tab + $vmGroupMembers + $cr)

                                 Write-Host ("Host Group: " + $hostGroupName)
                                 $line += ("Host Group: " + $hostGroupName + $cr)
                                 $hostGroupmembers = (Get-View -Property Name -Id ($clusterConfigExGroup| ?{($_ -is [VMware.Vim.ClusterHostGroup]) -and ($_.Name -eq $hostGroupName)}).Host | %{$_.Name}) -join ($cr + $tab)
                                 $line += ($tab + $hostGroupmembers + $cr)
                                 $line | Out-File -Append $Filename
                                 Write-Host $cr
                                }
                              }
                              }

                              • 12. Re: Managind DRS Groups via powercli
                                LucD Guru
                                User ModeratorsvExpertCommunity Warriors

                                You could also use the cmdlets in the DRSRule module Matt and myself wrote.

                                • 13. Re: Managind DRS Groups via powercli
                                  TWGarland Lurker

                                  You guys a geniuses.

                                   

                                  Albeit I work in Infrastructure. I am sure I could teach you things in a different arena.

                                   

                                  Beyond infrastructure I am dumb I need a simple script:

                                   

                                  1 Change ESX DRS settings to move all workloads from some hosts, to other hosts for backup purposes

                                   

                                  After this set DRS back to normal.

                                   

                                  Help....