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.
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
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
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
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
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
