CmdID / PowerShell / Cmdlets / Get
Get-Unique
Returns unique items from a sorted list. PowerShell reference
From the PowerShell reference
3 parameters
Alias gu
What it does
Returns unique items from a sorted list. The Get-Unique cmdlet compares each item in a sorted list to the next item, eliminates duplicates, and returns only one instance of each item. The list must be sorted for the cmdlet to work properly. Get-Unique is case-sensitive. As a result, strings that differ only in character casing are considered to be unique.
Get-Unique [-InputObject <PSObject>] [-AsString] [<CommonParameters>]Get-Unique [-InputObject <PSObject>] [-OnType] [<CommonParameters>]
Get unique words in a text file
$A = $( foreach ($line in Get-Content C:\Test1\File1.txt) {
$line.ToLower().Split(" ")
}) | Sort-Object | Get-Unique
$A.CountIdentifyGet unique integers in an array
1,1,1,1,12,23,4,5,4643,5,3,3,3,3,3,3,3 | Sort-Object | Get-UniqueIdentifyGet unique object types in a directory
Get-ChildItem | Sort-Object {$_.GetType()} | Get-Unique -OnTypeIdentifyGet unique processes
Get-Process | Sort-Object | Select-Object ProcessName | Get-Unique -AsStringIdentifyIts page in the reference: Get-Unique.
Parameters
-AsStringIndicates that this cmdlet uses the data as a string. Without this parameter, data is treated as an object, so when you submit a collection of objects of the same type to Get-Unique, such as a collection of files, it returns just one (the first). You can use this parameter to find the unique values of object properties, such as the file names.-InputObjectSpecifies input for Get-Unique. Enter a variable that contains the objects or type a command or expression that gets the objects.
This cmdlet treats the input submitted by using InputObject as a collection. it does not enumerate individual items in the collection. Because the collection is a single item, input submitted by using InputObject is always returned unchanged.-OnTypeIndicates that this cmdlet returns only one object of each type.