Miscbrah Posted March 27, 2012 Posted March 27, 2012 Hi - hope this is an easy one... I've found the following script which adds a user to a group in AD: DIM groupPath DIM userPath groupPath = "LDAP://cn=ITC Staff,cn=users,dc=wisesoft,dc=co,dc=uk" userPath = "LDAP://cn=test.3,cn=users,dc=wisesoft,dc=co,dc=uk" addToGroup userPath,groupPath SUB addToGroup(userPath, groupPath) DIM objGroup SET objGroup = GETOBJECT(groupPath) FOR EACH member in objGroup.members IF LCASE(member.adspath) = LCASE(userPath) THEN EXIT SUB END IF NEXT objGroup.Add(userPath) END SUB What I'd like to do is have the script reference a file (.csv maybe?) for multiple users to be added to a group at once. Just wanted to know how to go about that first off, and second off what sort of file would I need? If a .csv, what should be in it, or just really a list of names? Cheers for any help!
themightymrp Posted March 27, 2012 Posted March 27, 2012 Try this out, and yes use a CSV. It just needs to contain a column of Usernames that you want to add to the group. Modify to suit: ' Define main properties for script Dim strUserName Const ADS_PROPERTY_APPEND = 3 Const ForReading = 1 ' Open the CSV and seperate data into variables Set objFSO = Nothing set objTextFile = Nothing Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("C:\filename.csv", ForReading) Do While objTextFile.AtEndOfStream <> True strNextLine = objTextFile.Readline arrUSERData = split(strNextLine, ",") strUserName = arrUSERData(0) ' Add the account to the necessary security groups Set objGroup = GetObject _ ("LDAP://cn=groupname,OU=NameOfOU,dc=DomainName,dc=local") objGroup.PutEx ADS_PROPERTY_APPEND, "member", _ Array("cn=" & strUserName & ",ou=NameOfOU,dc=DomainName,dc=local") objGroup.SetInfo ' Clear variables ready for next line to be processed set strUserName = Nothing Loop objTextFile.Close 1
themightymrp Posted March 27, 2012 Posted March 27, 2012 No probs, hope it works. This is a snippet from a much larger script I use for creating user accounts from scratch. The full one presents a little box asking for firstname, surname, desired username and group (i.e. year 12, year 7, staff etc). It then creates the account, sets the password, profile, home directory, group membership and other bits. If you need/want a copy I can upload it. It does more than most people would actually need because of the way our AD was originally setup the script has to make the shares and set permissions on them rather than letting Windows do it
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now