Directory object not found error with Get-ADUser (and other cmdlets)

Say you want a spreadsheet of all users in the default Users OU. Easy. You open the Active Directory Module for Windows PowerShell and enter this cmdlet:

Get-ADUser -Filter * -SearchBase “OU=Users,DC=domain,DC=com” -Properties “Description” | fl Name, SamAccountName, Enabled, Description

And you get this error:

Get-ADUser : Directory object not found
At line:1 char:1
+ Get-ADUser -SearchBase “OU=Users,DC=domain,DC=com” -Filter * -Properties  …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [Get-ADUser], ADIdentityNotFoundException
    + FullyQualifiedErrorId : Directory object not found,Microsoft.ActiveDirectory.Management.Commands.GetADUser

“Directory object not found?” You say. “But I know there are user objects in there. I can see them in ADUC.”

Before you injure yourself banging your head on your desk, the fix is very simple. Change “OU=Users” to “CN=Users”. When you search the builtin OrganizationalUnits in Active Directory, you need to use CN instead of OU.

10 responses to “Directory object not found error with Get-ADUser (and other cmdlets)”

  1. Alberto Suarez says:

    Nice one. I was wondering what was wrong on my code haha 🙂

  2. Matthew says:

    I have a custom OU and with in that i have Users, changing it to “OU=MyOU, CN=Users” i get the error still.

    Trying with “CN=MyOU,CN=Users” also results in the error… any thoughts

    • jay c says:

      Try “OU=MyOU,OU=Users…”

      I’m not in a position to test it right now, but it can’t make the problem worse, right? I’ll test it when I get to the office tomorrow.

  3. jay c says:

    Heh. I just noticed that my example of the wrong way in the OP was actually the right way. I corrected it to be incorrect.

  4. jay c says:

    Matthew, how did you create the sub-OU? Was it created prior to upgrading your domain to 2008 (It seems to me that you used to be able to create OUs inside the default containers with an older version of AD.) or perhaps created using a third party tool or ADSIEdit? Using ADUC, you can’t create OUs under the builtin containers like Users or Computers.

    I would have expected “OU=MyOU,CN=Users…” to work. Since it doesn’t, I’m not sure what would.

    Is it feasible to move MyOU to another location within the tree?

  5. Davo says:

    Awesome! Worked for me! Thank you much!

  6. Raj says:

    Guru .. its worked .. gr8 .. thanks a lot 🙂

  7. Fazal says:

    Thanks a ton for the tip, I was banging my head..:)

  8. Dashihawk says:

    Thank you so much.. unfortunately i already had injured myself before i found this lol.

Leave a Reply

Your email address will not be published. Required fields are marked *