I think DSQUERY does exactly what you are asking for.
C:\>dsquery user -name MyAccount
"CN=MyAccount,OU=Accounts,OU=Persons,DC=child,DC=parent,DC=tld"
If it's important that your output only contain the OU
information, you can parse the output and redirect it to a file. Have this
script loop through your list of account names. You'd need to modify the
script to match your organization (you might not want exactly tokens 2 &
3).
@echo off
for /F "tokens=2,3 delims=," %%a in ('dsquery user -name %1') do echo %%a %%b >> c:\outputfile.txt
-
G

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Navroz Shariff
Sent: Wednesday, January 04, 2006 2:35 PM
To: [email protected]
Subject: RE: [ActiveDir] Locating which OU a specific use account is in
Well, my company has many departments each separted
in AD with its own OU. Having over 500 users, it is hard to find which specific
OU they are located. I am aware that I can perform a search in AD but having a
script handy would make it much easier in doing the search. In addition, having
a functionality to export the results to a file would be great for reporting
which user belongs to what department. I have gone around TechNet's script
center searching for what I want but all scripts regarding retrieving user
account property values need values for CN, OU, DC. What I am looking for is
knowing values for CN and DC when querying LDAP, would return the value for OU.
Thanks for all your replies.
-Nav
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Al Mulnick
Sent: Wednesday, January 04, 2006 12:57 PM
To: [email protected]
Subject: Re: [ActiveDir] Locating which OU a specific use account is in
Script? Have you seen Joeware.net's
adfind.exe ?
How about DSQUERY?
If you really wanted to do that in script you could. There's likely
enough examples to cobble together something like that on scriptcenter
(technet).
Does that help? If not, can you expand on why you would want to know the OU
a user is in? Do you need to write this to a file? Use it for something
else?
On 1/4/06, Navroz
Shariff <[EMAIL PROTECTED]>
wrote:
Dear list,Does anyone know of a script that, when a domain username is entered, would locate which OU the account is located in if, for the sake of argument, the OU structure in AD was designed in a way that user accounts were separated?Thanks advance,-Nav
