Powershell - Get-Unique Cmdlet
Cmdlet
Get-Unique cmdlet can be used to get the unique objects from a sorted list of objects.
In this example, we're see the Get-Unique cmdlet in action.
Step 1
In this example, we're set list of strings in a variable.
Type the following command in PowerShell ISE Console
$list = "one","two","two","three","four","five"
Step 2
In this example, we're printing the original list of strings.
Type the following command in PowerShell ISE Console
$list
Output
You can see following output in PowerShell console.
one two two three four five
Step 3
In this example, we're sorting the list and then get the unique values.
Type the following command in PowerShell ISE Console
$list | sort | get-unique
Output
You can see following output in PowerShell console.
five four one three two