Get-OneADObject
SYNOPSIS
Retrieves a single Active Directory object based on various criteria.
SYNTAX
Get-OneADObject [[-Identity] <Object>] [[-ObjectClass] <String>] [[-LDAPFilter] <String>]
[[-Properties] <String[]>] [-IncludeDeletedObjects] [[-Prompt] <String>] [<CommonParameters>]
DESCRIPTION
The `Get-OneADObject` function retrieves a single Active Directory object by querying based on identity, object class, LDAP filter, and additional properties. It supports interactive selection if multiple matches are found and can include deleted objects in the results.
EXAMPLES
EXAMPLE 1
Retrieves the Active Directory user object for "jdoe."
EXAMPLE 2
Get-OneADObject -Identity "CN=John Doe,OU=Users,DC=example,DC=com" -Properties "SamAccountName", "EmailAddress"
Retrieves the Active Directory object for "John Doe" and includes the `SamAccountName` and `EmailAddress` properties.
EXAMPLE 3
Retrieves a deleted computer object matching the specified LDAP filter.
PARAMETERS
-Identity
The identity of the Active Directory object to retrieve (e.g., DistinguishedName, SamAccountName, or GUID).
Type: Object
Parameter Sets: (All)
Aliases:
Required: False
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
-ObjectClass
The class of the Active Directory object to retrieve (e.g., User, Computer, Group). Defaults to '*'.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 2
Default value: *
Accept pipeline input: False
Accept wildcard characters: False
-LDAPFilter
An optional LDAP filter to refine the query.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Properties
A list of additional properties to retrieve for the object. Defaults to `DistinguishedName`.
Type: String[]
Parameter Sets: (All)
Aliases:
Required: False
Position: 4
Default value: @('DistinguishedName')
Accept pipeline input: False
Accept wildcard characters: False
-IncludeDeletedObjects
A switch parameter that, when specified, includes deleted objects in the query.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: 5
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-Prompt
A custom prompt message displayed when multiple matches are found and the user needs to select one.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 6
Default value: Get-OneADObject: select correct object from the list
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.