How to get unique objects while keeping the whole object

Was using Get-View to get a datastore list and I found that it returns duplicate items. 

I am pretty sure I do not have some 200+ datastores of the same name.

I do not know why, though a number of datastores are presented to multiple clusters, this could account for some of the duplicates.
I know it is _not_ multiples based on the number of hosts as the numbers are too small. In our environment we run eight node clusters, so if this was the case the numbers would be at least eight (8) times more. Further investigation required to determine what exactly is being returned and why there are some duplicates.

How to get the unique datastores? When using Select-Object with the -Unique parameter, only the Property selected will be passed through the pipeline. Not very helpful for what I wanted.

However the Sort-Object cmdlet has a -Unique parameter.

$fulllist = Get-View -ViewType Datastore
$uniquelist = $fulllist | Sort-Object -Property Name -Unique

With the above, datastore list went from 942 to 671 datastores.

Is this accurate? Could not tell you, too many to check manually. Something for another day. Yes we do have a large environment and this is not out of the ballpark.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.