Lets start with some data
$data =@(1,1,1,1,12,23,4,5,4643,5,3,3,3,3,3,3,37,7,7,8,9,9,0,0,12)
We now want to select the unique values out of this list
if I’ve wanted only the unique values I’ve tended to do this
$data | select –Unique
there are other options. If you want the output sorted you may be tempted by
$data | sort | select –Unique
but you can do this instead
$data | sort –Unique
or even
$data | sort -Unique –Descending
A final option is
$data | sort | Get-Unique
The input to Get-Unique must be sorted – it isn’t important to the other two methods
More info in the help files. Looks like PowerShell doesn’t have a unique method of getting unique values