Link to home
Start Free TrialLog in
Avatar of BlakeISS
BlakeISS

asked on

Bulk Creating User accounts from csv and adding them to groups

I have an open question regarding this for using ActiveRoles Management Shell but would entertain any method for accomplishing this task.  Any good scripts for also adding the users to specified groups?
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BlakeISS
BlakeISS

ASKER

Hi Rob,
This is great but I would also need it to be able to add the users to groups as well.
Are all users going to the same groups or different groups for each user?
Sorry, I should have indicated that.  The users would be going into the same groups.

Cheers,
Joe
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, I didn't mention that, but it is in the code as was indicated.  This is the DN of the new group to add users to:
strNewGroup = "CN=NewUsersGroups,OU=Main Office,OU=Sites," & objRootLDAP.Get("defaultNamingContext")

Regards,

Rob.
Do you have an example of what the group would look like?
Sure.

Assume your group is named New Users Group, and is in the following OU in ADUC:
domain.com\Sites\Main Office\

You then reverse the OU structure for the LDAP query, and have strNewGroup like so:
strNewGroup = "CN=New Users Group,OU=Main Office,OU=Sites," & objRootLDAP.Get("defaultNamingContext")

The defaultNamingContext part takes care of the domain.com specifics, but that translates to DC=domain,DC=com

One note, if the group if you're adding to is located in the *default* Users container in ADUC, then it would be:
strNewGroup = "CN=NewUsersGroups,CN=Users," & objRootLDAP.Get("defaultNamingContext")

because for some reason, the default Users container is a "container" rather than an "organization unit", hence the CN= instead of the OU=

Regards,

Rob.
In putting together the script with all input, this solution worked.  I am going to tweak it in hopes of being able to add in multiple groups.  
Thanks Much!
Great. Thanks for the grade.

To add more groups, change this:
strNewGroup = "CN=NewUsersGroups,OU=Main Office,OU=Sites," & objRootLDAP.Get("defaultNamingContext")

Open in new window


to this:
arrNewGroups = Array( _
   "CN=NewUsersGroup1,OU=Main Office,OU=Sites," & objRootLDAP.Get("defaultNamingContext"), _
   "CN=NewUsersGroup2,OU=Main Office,OU=Sites," & objRootLDAP.Get("defaultNamingContext"), _
   "CN=NewUsersGroup3,OU=Main Office,OU=Sites," & objRootLDAP.Get("defaultNamingContext") _
   )

Open in new window


and then also change this:
			Set objNewGroup = GetObject("LDAP://" & strNewGroup)
			objNewGroup.Add(objNewUser.ADsPath)
			objNewUser.SetInfo

Open in new window


to this:
			For Each strNewGroup In arrNewGroups
				Set objNewGroup = GetObject("LDAP://" & strNewGroup)
				objNewGroup.Add(objNewUser.ADsPath)
				objNewUser.SetInfo
			Next

Open in new window



and that should work fine.

Regards,

Rob.