vrm
Contributor
Contributor

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

Jump to solution

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

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

0 Kudos
12 Replies
LucD
Leadership
Leadership

Did you already try 5.  Re: DRS Reporting


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

0 Kudos
vrm
Contributor
Contributor

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

0 Kudos
vrm
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
vrm
Contributor
Contributor

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.

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
vrm
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
vrm
Contributor
Contributor

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

Cheers Vincent

0 Kudos
vrm
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
vrm
Contributor
Contributor

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

0 Kudos