Removing duplicate values from a PowerShell array

Eric Schoonover picture Eric Schoonover · Sep 8, 2009 · Viewed 200.1k times · Source

How can I remove duplicates from a PowerShell array?

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

Answer

Keith Hill picture Keith Hill · Sep 8, 2009

Use Select-Object (whose alias is select) with the -Unique switch; e.g.:

$a = @(1,2,3,4,5,5,6,7,8,9,0,0)
$a = $a | select -Unique