supermerio
supermerio

Reputation: 240

Remove duplicate entries from PowerShell object while keeping PSObject intact

I have created a PSObject with multiple properties. I would like to remove duplicate entries from the PSObject using a specific property as a reference.

I'd like to do this while keeping the PSObject in its original format.

Examples I have seen extract the non-duplicate values. I want to delete the duplicate values.

I'm trying to turn this:

DistinguishedName                             Name    
-----------------                             ----
OU=Users,DC=Domain,DC=Local                   Users
OU=Users,DC=Domain,DC=Local                   Users

Into this:

DistinguishedName                             Name    
-----------------                             ----
OU=Users,DC=Domain,DC=Local                   Users

I have a feeling i'm missing a trick here...

Thanks

Upvotes: 2

Views: 15935

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174505

That looks like the Format-Table output of a collection of PSObjects with the same properties.

To weed out duplicates, use Sort-Object -Unique:

$uniqObjects = $psobjects |Sort-Object -Unique

Upvotes: 3

Related Questions