Export (0) Print
Expand All
Expand Minimize
7 out of 11 rated this helpful - Rate this topic

Using the Get-Unique Cmdlet

Listing the Unique Members of a Collection

Given a sorted collection of items, the Get-Unique cmdlet returns just the unique items in that collection.

What does that mean? Well, suppose the text file C:\Scripts\Test.txt contains the following:



apple
banana
grapefruit
apple
apple
banana
grapefruit
apple
pear
apple
apple
apple
peach
banana
pear

To determine the unique items in this collection, we can read the text file, sort it, then run the sorted list through Get-Unique. In other words, we can do this:



Get-Content c:\scripts\test.txt | Sort-Object | Get-Unique

And here’s what we get back:



apple
banana
grapefruit
peach
pear

Get-Unique Aliases
  • gu

Related Links

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.