views:

1171

answers:

2

How can I remove duplicates from a PowerShell array.

$a = @(1,2,3,4,5,5,6,7,8,9,0,0)
+11  A: 

Use Select -uniq e.g.:

$a = @(1,2,3,4,5,5,6,7,8,9,0,0)
$a = $a | select -uniq
Keith Hill
you deserve your MVP, thanks again
spoon16
That was too easy :-(. In PowerShell 2 you can also use `Get-Unique` (or `gu`) if your array is already sorted.
Joey
Johannes, Get-Unique is available in v1 :)
Shay Levy
+5  A: 

Another option:

$a | sort -unique

Shay Levy