October 15th, 2015

PowerTip: Get Unique Numbers from Array

Doctor Scripto
Scripter

Summary: Learn how to get unique numbers from an array.

Hey, Scripting Guy! Question How can I use Windows PowerShell to return only the numbers that are unique in an array?

Hey, Scripting Guy! Answer Sort the array of numbers, then pipe the output to the Get-Unique cmdlet, for example:

$a = 1,2,7,6,4,3,3,2,9

$a | sort | Get-Unique

Note  Sort is an alias for the Sort-Object cmdlet.

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.