VMware Cloud Community
vrm
Contributor
Contributor
Jump to solution

Retreive a list of vm's in a virtual machine DRS group

Hello,

I want to retreive a list of vm's in a virtual machine DRS group. I found the following oneliner but the output is empty. I am using Powercli 5.5 release 1 and vSphere 5.5 update1

(Get-Cluster CLUSTER).ExtensionData.ConfigurationEx.Group| ?{$_.vm} | %{" GROUP ${$_.name} found in this cluster"; foreach($CurrentVM in $_.vm) { (Get-View-id $CurrentVm).name } }

Need some help Smiley Happy

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

No problem, we add an extra condition to the Where-clause

$clusterName = "MyCluster"
$vmGroupName = "VMgroup"

(
Get-Cluster -Name $clusterName).ExtensionData.ConfigurationEx.Group |
Where {$_ -is [VMware.Vim.ClusterVmGroup] -and $_.Name -eq $vmGroupName} | %{
 
Get-View $_.VM | Select @{N="VMgroupVM";E={$_.Name}}
}


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

View solution in original post

Reply
0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

Did you already try 5.  Re: DRS Reporting


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

Reply
0 Kudos
vrm
Contributor
Contributor
Jump to solution

Hello Luc,

Thank you for your answer. The script works. I'm now using the output of "VMgroupVM" as input for another script!

Many thanks,

Vincent

Reply
0 Kudos
vrm
Contributor
Contributor
Jump to solution

Hello Luc,

A last question. The output is formatted as follow:

VMgroupVM

"server1;server2;server3"


Is it possible to change the outut in the following format:

VMgroupVM

"server1"

"server2"

"server3"


Cheers,

Vincent

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is possible, but how would you like to display multiple VM groups on the cluster ?

Like this ?

VMgroup,VM

group1,VM1

group1,VM2

group1,VM3

group2,VM10

group2,VM11


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

Reply
0 Kudos
vrm
Contributor
Contributor
Jump to solution

I'm only exporting VMgroupVM, so the vm names only are enough. I'm using the output as inputfile for logging vm's in one specific vm drs rulegroup.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then you can do something like this

$clusterName = "MyCluster"

(
Get-Cluster -Name $clusterName).ExtensionData.ConfigurationEx.Group |
Where {$_ -is [VMware.Vim.ClusterVmGroup]} | %{
 
Get-View $_.VM | Select @{N="VMgroupVM";E={$_.Name}}
}


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

Reply
0 Kudos
vrm
Contributor
Contributor
Jump to solution

This is what I need to export. I'm missing one thing. I need to define the specific VMgroup.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No problem, we add an extra condition to the Where-clause

$clusterName = "MyCluster"
$vmGroupName = "VMgroup"

(
Get-Cluster -Name $clusterName).ExtensionData.ConfigurationEx.Group |
Where {$_ -is [VMware.Vim.ClusterVmGroup] -and $_.Name -eq $vmGroupName} | %{
 
Get-View $_.VM | Select @{N="VMgroupVM";E={$_.Name}}
}


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

Reply
0 Kudos
vrm
Contributor
Contributor
Jump to solution

Great work! Many many thanks!!! You earned a vBeer Smiley Wink

Cheers Vincent

Reply
0 Kudos
vrm
Contributor
Contributor
Jump to solution

Is it possible to use PowerCLI to add vm's to a VM DRS group?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not with a cmdlet I'm afraid.

But you can use the API, see for example   Re: How to modify an existing Virtual Machine DRS -Group?


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

Reply
0 Kudos
vrm
Contributor
Contributor
Jump to solution

That's it! Thank you for the quick reply.

Reply
0 Kudos