Search code examples
arrayspowershell

Removing duplicate values from a PowerShell array


How can I remove duplicates from a PowerShell array?

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

Solution

  • 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