Home » PowerShell » Fix: Get-Aduser : Directory Object not found

Fix: Get-Aduser : Directory Object not found

The Get-AdUser cmdlet in PowerShell gets one or more active directory users based on the specified search criteria.Get-AdUser: Directory object not found error can be because of the incorrect object name (distinguished name of the object) while trying to retrieve the users.

While trying to get active directory users, I got the below error on the PowerShell terminal,

PS C:\> Get-ADUser -Filter * -SearchBase "OU=SHELUsers,DC=SHELLPRO,DC=LOCAL" -Properties "Description" | Select Name, SamAccountName
Get-ADUser : Directory object not found
At line:1 char:1
+ Get-ADUser -Filter * -SearchBase “OU=SHELUsers,DC=SHELLPRO,DC=LOCAL”  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [Get-ADUser], ADIdentityNotFoundException
    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundExcept
   ion,Microsoft.ActiveDirectory.Management.Commands.GetADUser

After troubleshooting, the solution to this issue is to use the correct distinguished name.

In this article, we will discuss how to troubleshoot and solve the Get-AdUser: Directory Object not found in PowerShell.

Directory Object Not Found – Quick Fix

If you have also got the Get-AdUser: Directory Object not found when you try to get the list of users from the active directory, it might be because of the incorrect distinguished name being used.

Get-AdUser: Directory Object not found
Get-AdUser: Directory Object not found

CategoryInfo : ObjectNotFound: (:) [Get-ADUser], ADIdentityNotFoundException and FullQualifiedErrorId shows the details of the exception as ADIdentityNotFoundException

Refer to the following steps to get the correct distinguishedName

  1. Open the ADSI Edit and connect to the Default naming context
  2. Select the Object from where you want to retrieve the adusers
  3. Right Click on it and select the Properties
  4. Check the distinguishedName attribute.
  5. Use the same distinguishedName in your Get-AdUser command.
ADSI - Directory Object DistinguishedName
ADSI – Directory Object DistinguishedName

Note here, earlier, we used distinguishedName as “OU=SHELUsers,DC=SHELLPRO,DC=LOCAL” to get users, however, the users we want to retrieve are available in the OU=SHELLUsers object. Hence its distinguishedname should be used “OU=SHELLUSERS,DC=SHELLPRO,DC=LOCAL“

After making the necessary changes in the distinguishedname in the Get-AdUser command, it retrieves the adusers.

Get-ADUser -Filter * -SearchBase "OU=SHELLUsers,DC=SHELLPRO,DC=LOCAL"| Select SamAccountName

The output of the above PowerShell script lists the aduser from the OU.

Get-AdUser - List all the users
Get-AdUser – List all the users

The most common for the “Get-AdUser: Directory Object is not found” issue is either the distinguishedname is incorrect or the users we want to retrieve may be available in different objects, like CN=USERS as Users is a container and not OU.

Conclusion

I hope the above article on how to fix the Get-AdUser: Directory Object not found is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.