We help IT Professionals succeed at work.

Extract the canonical name of object (users) from AD?

Hi All,

Does anyone know if its possible to extract the object location path of all users in AD? for example when you look at advanced properties of users and select the object tab it gives you the full path to the location of the user?


Watch Question

dsquery user -name MJB2011

Use for loop for a list of users


I want to query a OU all users in all subfolders?
This is very simple to do.

DSquery OU "distinguished name of ou"

You can use ADsiedit or ADexplorer to get the distinguished name of the OU.

Disregard that my mistake if you want users you would need to do.

DSquery user "distinguished name of OU"

The first one would show OUs under that not users.
Top Expert 2013

There is no path for the OU in the user properties so that can't be extracted but you can extract the full DN of a user.  Would that be helpful?


Also if you want more information you can always pipe the dsquery command into the DSget command.

DSquery user "distinguished name of OU" | DSget user -ln -fn -tel

Examples of DSget can be found here.


Just tried query:

dsquery user domain.ctb/city/Users

Fails with: dsquery failed:Value for `startnode' has incorrect format.



Yes i simply want a list of all users with there full DN for example:

domain.ctb/city/Users/admin/bloggs, joe
domain.ctb/city/Users/admin/bloggs, moe
domain.ctb/city/Users/finance/bloggs, floe
domain.ctb/city/Users/finance/bloggs, doe
MJB the dsquery failed because you did not put the correct distinguished name of your OU in there.

dsquery user domain.ctb/city/Users

it should be something like

dsquery user OU=users, OU=City,DC=domain,DC=ctb

You can do this in PowerShell (using 2008 R2 AD cmdlets) for an OU as follows:

Get-ADUser -filter * -SearchBase "ou=SpecifiedOU,dc=YourDomain,dc=Com" | Select-Object *

If you want something that will return the distinguishedName of each user object in your domain:

Get-ADUser -filter * -SearchBase "dc=YourDomain,dc=Com" | Select-Object distinguishedName

You can add other attributes to return, such as sAMAccountName, givenName, surName, etc.