+ Post New Thread
Results 1 to 4 of 4
Scripts Thread, Change vbs script (add user to group) to add multiple users in Coding and Web Development; Hi - hope this is an easy one... I've found the following script which adds a user to a group ...
  1. #1

    Miscbrah's Avatar
    Join Date
    Dec 2011
    Posts
    900
    Thank Post
    247
    Thanked 253 Times in 152 Posts
    Rep Power
    114

    Smile Change vbs script (add user to group) to add multiple users

    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!

  2. #2
    themightymrp's Avatar
    Join Date
    Dec 2009
    Location
    Leeds, West Yorkshire
    Posts
    1,204
    Thank Post
    212
    Thanked 223 Times in 192 Posts
    Rep Power
    72
    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:

    Code:
    '	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

  3. Thanks to themightymrp from:

    Miscbrah (27th March 2012)

  4. #3

    Miscbrah's Avatar
    Join Date
    Dec 2011
    Posts
    900
    Thank Post
    247
    Thanked 253 Times in 152 Posts
    Rep Power
    114
    Leg-
    wait for it
    -end.

    Thanks

  5. #4
    themightymrp's Avatar
    Join Date
    Dec 2009
    Location
    Leeds, West Yorkshire
    Posts
    1,204
    Thank Post
    212
    Thanked 223 Times in 192 Posts
    Rep Power
    72
    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

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 8
    Last Post: 19th April 2012, 04:29 PM
  2. Replies: 0
    Last Post: 20th October 2011, 12:45 PM
  3. Replies: 4
    Last Post: 23rd August 2011, 03:31 PM
  4. Replies: 5
    Last Post: 14th June 2008, 12:18 AM
  5. Replies: 21
    Last Post: 11th July 2006, 07:37 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •