Skip to content

Select-Unique

SYNOPSIS

Select unique objects based on specified properties.

SYNTAX

Select-Unique [-Property] <String[]> -InputObject <Object> [-AsHashtable] [-NoElement] [<CommonParameters>]

DESCRIPTION

This function filters a collection of objects to return only unique objects based on the specified properties. It supports output as a hashtable and allows excluding elements from the output.

EXAMPLES

EXAMPLE 1

$data | Select-Unique -Property "Name"

Returns unique objects from `$data` based on the "Name" property.

EXAMPLE 2

$data | Select-Unique -Property "Name", "ID" -AsHashtable

Returns a hashtable of unique objects from `$data` based on the "Name" and "ID" properties.

EXAMPLE 3

$data | Select-Unique -Property "Name" -AsHashtable -NoElement

Returns a hashtable of unique keys without elements.

PARAMETERS

-Property

The property or properties to use for determining uniqueness.

Type: String[]
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-InputObject

The input objects to be filtered for uniqueness. Accepts pipeline input.

Type: Object
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-AsHashtable

A switch to return the results as a hashtable instead of objects.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-NoElement

A switch to exclude elements from the hashtable when using the `AsHashtable` parameter.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

NOTES