VMware Cloud Community
andershansendk
Contributor
Contributor
Jump to solution

Select name

Hi

When i am running get-cluster | select name

I get this output:

Name
----
Name_of_cluster

When i put

$clusters = get-cluster | select Name

Write-host "$clusters"

I get this output:

@{Name=Name_of_Cluster}

Is it posible to get "pretty" output when I use it in a script?

Blog: www.vperformance.org
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The Select-Object cmdlet returns an array of PSCustomObjects objects.

That's why you see the '@{...}', which indicates an array.

And the 'Name=Name_of_Cluster', which is the property in the PSCustomObjects object.

You want the value of Name property in your output, not the complete object.

You could do

$clusters = get-cluster | select Name 
$clusters
| %{$_.Name}

or perhaps even better, don't use the Select-Object when you store the objects internally.

$clusters = get-cluster 
$clusters
| %{$_.Name}


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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

The Select-Object cmdlet returns an array of PSCustomObjects objects.

That's why you see the '@{...}', which indicates an array.

And the 'Name=Name_of_Cluster', which is the property in the PSCustomObjects object.

You want the value of Name property in your output, not the complete object.

You could do

$clusters = get-cluster | select Name 
$clusters
| %{$_.Name}

or perhaps even better, don't use the Select-Object when you store the objects internally.

$clusters = get-cluster 
$clusters
| %{$_.Name}


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

Reply
0 Kudos
andershansendk
Contributor
Contributor
Jump to solution

Just was I was looking for, thank you for the fast response.

Blog: www.vperformance.org
Reply
0 Kudos