Eliminating Duplicates

by Mar 4, 2014

Sort-Object has an awesome feature: with the parameter -Unique, you can remove duplicates:

This can be applied to object results, as well. Check out this example: it will get you the latest 40 errors from your system event log:

This may be perfectly fine, but depending on your event log, you may also get duplicate entries.

With -Unique, you can eliminate duplicates, based on multiple properties:

You will no longer see more than one entry with the same InstanceID AND Message.

You can then sort the result again, to get back the chronological order:

So bottom line is: Sort-Objects parameter -Unique can be applied to multiple properties at once.

Twitter This Tip! ReTweet this Tip!