VMware Cloud Community
vStout_Bill
Contributor
Contributor
Jump to solution

VMware.Vim.ClusterVMGroup returned instead of groupnames from ExtensionData.Configurationex.Group

When I run a powershell query to find groupnames in ExtensionData.Configurationex.Group I see the groupnames expected.

PowerCLI C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts> Get-cluster | Select Name,@{Name="Group";Expression={$_.Ex

tensionData.Configurationex.Group}} | ?{$_.Name -like "lax-devtest*"}

Name                                                              Group

----                                                              -----

lax-devtest4                                                      {mssql-vm, winsvr-vm, mssql-hosts, winsvr-hosts}

lax-devtest1

lax-devtest3                                                      VMware.Vim.ClusterVmGroup


However if I change the output type (html, csv, etc.) I don't see the gorupnames. 


PowerCLI C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts> Get-cluster | Select Name,@{Name="Group";Expression={$_.Ex

tensionData.Configurationex.Group}} | ?{$_.Name -like "lax-devtest*"}  | export-csv c:\tmp\getcluster.csv

#TYPE Selected.VMware.VimAutomation.ViCore.Impl.V1.Inventory.ClusterImpl

Name

Group

lax-devtest4

VMware.Vim.ClusterVmGroup VMware.Vim.ClusterVmGroup VMware.Vim.ClusterHostGroup VMware.Vim.ClusterHostGroup

lax-devtest1

lax-devtest3

VMware.Vim.ClusterVmGroup

Why does other output types return VMware.Vim.ClusterVmGroup instead of the names?  This also affects searches since only VMware.Vim.ClusterVmGroup is seen when looking for names.


Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

My bad, you should of course extract the name, otherwise you will get the name of the object behind the property.

Try like this

Get-cluster | Select Name,
@{Name="Group";Expression={[string]::Join(',',($_.ExtensionData.Configurationex.Group | Select -ExpandProperty Name))}}


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

That is because the calculated property Group is an array (indicated by the curly braces in the output).

The PowerShell output routine knows how to handle this, bu the cmdlets like ExportTo-Csv don't.

A solution is to convert the array into a string.

Something like this

@{Name="Group";Expression={[string]::Join(',',($_.ExtensionData.Configurationex.Group)}}



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

Reply
0 Kudos
vStout_Bill
Contributor
Contributor
Jump to solution

Converting the array into a string obscures the group names on the console.

PowerCLI C:\Program Files\VMware\Infrastructure\vSphere PowerCLI> Get-cluster | Select Name,@{Name="Group";Expression={[string]::Join(',',($_.ExtensionData.Configurationex.Group))}

}  | ?{$_.Name -like "lax-devtest*"}

Name                                                              Group

----                                                              -----

lax-devtest4                                                      VMware.Vim.ClusterVmGroup,VMware.Vim.ClusterVmGroup,VMware.Vim...

lax-devtest1

lax-devtest3                                                      VMware.Vim.ClusterVmGroup

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

My bad, you should of course extract the name, otherwise you will get the name of the object behind the property.

Try like this

Get-cluster | Select Name,
@{Name="Group";Expression={[string]::Join(',',($_.ExtensionData.Configurationex.Group | Select -ExpandProperty Name))}}


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

Reply
0 Kudos
vStout_Bill
Contributor
Contributor
Jump to solution

LucD, awesome as usual for the last few years!

This solved the problem I was really trying to address, which is search by groupnames.

PowerCLI C:\Program Files\VMware\Infrastructure\vSphere PowerCLI> Get-cluster | Select Name,@{Name="Group";Expression={[string]::Join(',',($_.ExtensionData.Configurationex.Group | Select -ExpandProperty Name))}} | ?{$_.Group -like "mssql*"}

Name                                                              Group

----                                                              -----

lax-devtest4                                                      mssql-vm,winsvr-vm,mssql-hosts,winsvr-hosts

lax-devtest3                                                      mssql-vm

Reply
0 Kudos