PowerCLI

 View Only
Expand all | Collapse all

Powercli Script for Getting VMHost Groups and VMHost Group Members

  • 1.  Powercli Script for Getting VMHost Groups and VMHost Group Members

    Posted Feb 13, 2019 10:37 AM

    Hi All

     

    Is there a way to get the VMhost Group and All vm's in a VMHostGroup using Powercli?

    Also, I would like to add multiple VM's to different VMhost Groups. Is it possible via POwercli?

     

    Thank you all

    Sunny



  • 2.  RE: Powercli Script for Getting VMHost Groups and VMHost Group Members

    Posted Feb 13, 2019 11:15 AM

    I assume you mean all VMs in a VMGroup?
    Host are in a HostGroup.

    But yes, with the Get-DrsClusterGroup cmdlet.

    Get-DrsClusterGroup -Type VMGroup

    And yes, with the Set-DrsClusterGroup cmdlet.

    Set-DrsClusterGroup -VM NewVM -DrsClusterGroup MyGroup -Add



  • 3.  RE: Powercli Script for Getting VMHost Groups and VMHost Group Members

    Posted Feb 14, 2019 04:52 AM

    Hi Lucd,

    Thank you for a quick response. The powershell command you recommended gives me only half the information that i needed

    Get-DrsClusterGroup -Type VMHostGroup -Name XXX-XX3

    The above command give me all the ESX hosts that are part of the group.

    Am trying to Retrieve all vm's part of the Drsvmhostrule and add more vm's to the rule. DRSVMhostrule and all the vm's in this+

    that would be something like

    Get-DrsVMHostRule -Type MustRunOn -name "VMs must run in XXX" | Get-VM



  • 4.  RE: Powercli Script for Getting VMHost Groups and VMHost Group Members

    Posted Feb 14, 2019 07:03 AM

    You are using -Type VMHostGroup, for the VM groups you need -Type VMGroup (like I showed in my previous reply).



  • 5.  RE: Powercli Script for Getting VMHost Groups and VMHost Group Members

    Posted Feb 19, 2019 02:42 AM

    Hi LucD

    i've changed the powercli command as per your suggestions.

    For some reason all vm's that are part of the VMGroup are not displayed

    Get-DrsClusterGroup -Type VMGroup -name "VMs for Sy" | select Member

    Output as below

    Member                                                 

    ------                                                 

    {VM1, VM01, VM03, VMfr...}

    I know i have more vm's in this list (close to 40 VM's)



  • 6.  RE: Powercli Script for Getting VMHost Groups and VMHost Group Members
    Best Answer

    Posted Feb 19, 2019 07:39 AM

    PowerShell shows only what it can on your console.
    All the values should be there.
    Try like this

    Get-DrsClusterGroup -Type VMGroup -Name DrsGroup |

    select -ExpandProperty Member



  • 7.  RE: Powercli Script for Getting VMHost Groups and VMHost Group Members

    Posted Feb 20, 2019 12:40 AM

    Hi Lucd

    Thanks for the reply.

    Get-DrsClusterGroup -Type VMGroup -Name DrsGroup |

    select -ExpandProperty Member

    The above is what am after.



  • 8.  RE: Powercli Script for Getting VMHost Groups and VMHost Group Members

    Posted Feb 20, 2019 01:24 AM

    Hi Lucd

    the Get-DRSClusterGroup gives all the vm's that are part of the group

    I've just tried to add some vm's using Set-DRSclustergroup -Type VMgroup -Name XXXX -VM "XXXX" and it throws the error mesg

    Set-DrsClusterGroup : A parameter cannot be found that matches parameter name 'Type'.

    Whats is the best way to add vm's to a VMHost rule?

    I've 2 Host rules

    1) VM Must run in Sy1

    2) VM Must run in Sy2

    4 VM/Host Groups

    1) SY1 Hosts

    2) Sy2 Hosts

    3) Sy1 vm's

    2) Sy2 VM's

    I would like to add vm's to different host rules. Whats the best way to achive this



  • 9.  RE: Powercli Script for Getting VMHost Groups and VMHost Group Members

    Posted Feb 20, 2019 06:51 AM

    Try like this

    Get-DrsClusterGroup -Name MyGroup -Type VMGroup |

    Set-DrsClusterGroup -VM vm1,vm2 -Add



  • 10.  RE: Powercli Script for Getting VMHost Groups and VMHost Group Members

    Posted Dec 01, 2022 01:09 AM

    the commandlets Get/Set-DrsClusterGroup dosent seems to be working (return null values) in vSphere 7, any idea why? any alternate way for vSphere7 ?



  • 11.  RE: Powercli Script for Getting VMHost Groups and VMHost Group Members

    Posted Dec 01, 2022 01:12 AM

    ShoHRock_0-1669857109138.png



  • 12.  RE: Powercli Script for Getting VMHost Groups and VMHost Group Members

    Posted Dec 01, 2022 08:49 AM

    There seem to be no VM nor VMHost groups in those rules.

    Just tested, Get-DrsClusterGroup and Set-DrsClusterGroup work for me.



  • 13.  RE: Powercli Script for Getting VMHost Groups and VMHost Group Members

    Posted Feb 19, 2019 03:25 PM

    Here's what I use to backup my DRS settings in all of our vCenters & Clusters. I would do a backup, edit the CSV file, and do a restore. I will past the restore script if you want it as well.

    $vCenters = Get-Content "XXX.csv"

    foreach ($vCenter in $vCenters)

    {

    Connect-VIServer $vCenter -WarningAction SilentlyContinue

    $outpath = "XXX"

    $outfile = $outpath + "Rules_" + $vCenter + ".csv"

    $rules = Get-Cluster -server $vCenter | Get-DrsRule

    $output=@()

    if ($rules -ne $NULL)

    {

    foreach($rule in $rules){

       $line=""|Select Cluster,Name,Enabled,KeepTogether,VM1,VM2

       $line.cluster = (Get-View -Id $rule.ClusterId).Name

       $line.name = $rule.Name

       $line.Enabled = $rule.Enabled

       $line.KeepTogether = $rule.KeepTogether

       $line.VM1 = (get-view -id ($rule.VMIds)[0]).name

       $line.VM2 = (get-view -id ($rule.VMIds)[1]).name

       $output+=$line

    }

    }

    $output | Export-CSV -notypeinformation $outfile

    Disconnect-VIServer $vCenter -Confirm:$false

    }



  • 14.  RE: Powercli Script for Getting VMHost Groups and VMHost Group Members

    Posted Feb 19, 2019 03:27 PM

    That doesn't include the groups that are not used in a rule.