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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Multiple Security Groups 1

Status
Not open for further replies.

Divaldo

Technical User
Sep 18, 2007
18
0
0
GB
Does anyone know how to script the creation of multiple security groups in AD?

I have a script that works fine creating one group for a class in our school:

Const ADS_GROUP_TYPE_LOCAL_GROUP = &h2
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000

Set objOU = GetObject("LDAP://ou=classes,ou=students,ou=managed users,dc=mydomain,dc=com")
Set objGroup = objOU.Create("Group", "cn=12aMs")

objGroup.Put "sAMAccountName", "12aMs"
objGroup.Put "groupType", ADS_GROUP_TYPE_LOCAL_GROUP Or _
ADS_GROUP_TYPE_SECURITY_ENABLED
objGroup.SetInfo

However i need to create groups for all of our classes, is there way of copying that, pasting it below and changing the class name in the script and getting it to run again?

Or pulling the names from CSV and then creating them all?

Many thanks.
 
Sure, you could make the group names variables and pull that info from Excel or a CSV.

I think my FAQ on the subject will help you understand the concepts.

faq329-4871

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks very much for your post, i'm afraid i'm pretty new to the scripting side of things, so most of that went waaaaay over my head!!

I'm still trying to get my head round it though.
 
Set objOU = GetObject("LDAP://ou=classes,ou=students,ou=managed users,dc=mydomain,dc=com")

For i = 1 To 12
Set objGroup = objOU.Create("Group", "cn=" & CStr(i) & "aMs")

objGroup.Put "sAMAccountName", CStr(i) & "aMs"
objGroup.Put "groupType", ADS_GROUP_TYPE_LOCAL_GROUP Or _
ADS_GROUP_TYPE_SECURITY_ENABLED
objGroup.SetInfo
Set objGroup = Nothing
Next

'you will want to consider a pre-check to see if the gropu already exists... etc etc
 
Excellent!!!

That has sorted me out.

Thanks very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top