I need help writing a script that will export only users in a specific "OU",
any help would be great, thanks!!

Re: export users in an OU by Richard

Richard
Fri Dec 26 11:35:48 CST 2003

JC wrote:

> I need help writing a script that will export only users in a specific
"OU",
> any help would be great, thanks!!

Hi,

I don't know what you intend to do with the users, but the simplest approach
would be to bind to the OU container in AD, filter on objects of class
"user", and enumerate the users in the OU in a "For Each" loop. For example,
to output the NT names (the "pre-Windows 2000 logon name") of all users in
the ou=Sales container of the MyDomain.com domain:

Set objOU = GetObject("LDAP://ou=Sales,dc=MyDomain,dc=com")
objOU.Filter = Array("user")

For Each objUser In objOU
Wscript.Echo objUser.sAMAccountName
Next

This should be run at a command prompt using the cscript host. The output
can be redirected to a text file. For example, if the VBScript above is in a
file called EnumUsers.vbs, you would execute the following at a command
prompt to export a list of usernames to a text file called Users.txt

cscript //nologo EnumUsers.vbs > Users.txt

--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--