Remove duplicates

Often i need to remove duplicates in objects before pipe them to another function, or before print the result.

So, let’s take a cmdlet which return many lines like Get-Process

1

 

 

 

 

 

 

 

 

Now, let’s remove duplicates from the output… Two methods exist for this task…

The first one:

2

 

 

 

The second method:

3

 

 

 

 

Ok, which one should i use ? Kinda difficult to answer that, two of them return exactly the same output… The main difference between them is performance related, look at this !

4

 

 

 

 

 

5

 

 

 

 

 

Ok, we talk only about Milliseconds, but clearly on bigger objects collection it could be far better.

Hope you’ll find how to use this.

See ya!