Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch Add users to AD groups

Status
Not open for further replies.

RogerGoncalves

Technical User
Sep 1, 2005
2
PT
Hi,

I'm looking for a way to bulk add users to a specific Global Group.
I have a textfile with all usernames and would like to use that file to import into a group
Addusers from resource kit isn't very practical because tall users have to be ina s single line:
[Global]
GlobalGroupName, Comment, Username, Username,...

Any help ?
 
A command-line version:
Code:
FOR /F %i IN (textfile.txt) DO net group groupname %i /add /domain
VBScript could be used as well. Note that if you use the above in a batch script (.bat/.cmd file) you need to double the percent signs (%%i)
 
This is fairly simple for vbscript.

Code:
Const ADS_PROPERTY_APPEND = 3
 
Set objGroup = GetObject _
    ("LDAP://cn=Atl-Users,cn=Users,dc=NA,dc=fabrikam,dc=com")
objGroup.PutEx ADS_PROPERTY_APPEND, _
    "member", Array("cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objGroup.SetInfo

What you will want to do is modify the above to be coded for the LDAP path for your group. For the user portion, you can read from your text file and use a function to get the users LDAP path. faq329-5688 has the function you need to get the LDAP from the samAccountName (login name).

Take a look at my FAQ faq329-4871 for how to read from your text file and my other FAQ faq329-5798 for samples on using the function to get the user LDAP.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Thank you all, for this info.
I used the batch from crobin1 as it was realy simple, but am looking into the vbscript code, as I want to recreate an AD in our preproducion environment, and want to be able to quickly recreate the AD users, OUs and groups to test changes in aplications.

Thank you all

Rogerio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top