Skip to content

/errors/active-directory/cannot-find-an-object-with-identity

Get-ADUser : Cannot find an object with identity: 'jdoe' under: 'DC=contoso,DC=com'

The commands on this page have not been executed by our verification runner yet.updated
tool
Active Directory PowerShell
exit code
1
versions
ActiveDirectory module (RSAT) on Windows 10/11 and Windows Server 2016+
os
windows

Get-ADUser : Cannot find an object with identity: 'jdoe' under: 'DC=contoso,DC=com'. means the domain controller found no user that matches the -Identity value in that domain. -Identity accepts only a distinguished name, GUID, SID or sAMAccountName; a UPN, email address or display name does not match, even when the user exists. Search those with -Filter instead:

powershell
Get-ADUser -Identity jdoe                                          # sAMAccountName
Get-ADUser -Filter "UserPrincipalName -eq 'jdoe@contoso.com'"      # UPN
Get-ADUser -Filter "mail -eq 'john.doe@contoso.com'"               # email
Get-ADUser -Filter "DisplayName -eq 'John Doe'"                    # display name

The text after under: is the naming context that was searched. If it is not the domain where the account lives, that is the cause.

What -Identity accepts

FormExample
sAMAccountNamejdoe
Distinguished nameCN=John Doe,OU=Staff,DC=contoso,DC=com
objectGUID6f7c1a4e-0000-0000-0000-000000000000
SIDS-1-5-21-...-1104

The other Get-AD* cmdlets (Get-ADGroup, Get-ADComputer) follow the same rule for their object class; Get-ADObject -Identity accepts only a distinguished name or GUID.

Account in another domain

The module searches the domain of the computer (or of the -Server you pass). For a user in a child or trusted domain, name a domain controller of that domain:

powershell
Get-ADUser -Identity jdoe -Server emea.contoso.com

For a forest-wide search, query a global catalog (port 3268) with -Filter; the global catalog holds a partial set of attributes.

Test whether an account exists in a script

Get-ADUser -Identity throws when nothing matches, while Get-ADUser -Filter returns nothing. Either pattern works:

powershell
try {
  $u = Get-ADUser -Identity $name -ErrorAction Stop
} catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
  Write-Warning "No user $name in this domain"
}

$u = Get-ADUser -Filter "sAMAccountName -eq '$name'"
if (-not $u) { Write-Warning "No user $name" }

If the module cannot reach any domain controller at all, the error is a different one: Unable to find a default server with Active Directory Web Services running. Filter syntax is covered in Get-ADUser -Filter.

Sources