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?
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
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
Just was I was looking for, thank you for the fast response.