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?

Thanks

matt
Comment
Watch Question

dsquery user -name MJB2011

Use for loop for a list of users

Author

Commented:
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.
http://technet.microsoft.com/en-us/sysinternals/bb963907

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

Commented:
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?



Thanks

Mike
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.
http://tmdnet.nothave.com/book/OS/MANUALS/COMMANDS/D/DSGET.HTM

Author

Commented:
Just tried query:

dsquery user domain.ctb/city/Users

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

Author

Commented:
MKline71:

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


Commented:
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.