How can I use a script to add users to an Active Directory (AD) group?

A. First, you connect to a group via a script, as the following code shows:


set objGroup = GetObject("LDAP://CN="secgroup,ou=testing,dc=savilltech,dc=com")

Then you add members to the group via the PutEx function.

Const ADS_PROPERTY_APPEND = 3 objGroup.PutEx ADS_PROPERTY_APPEND, _ "member", Array("cn=user1,dc=savilltech,dc=com") if err.number0 then wscript.echo "Error adding to group " & err.number, err.description err.Clear end if


You can have multiple users in the array to be added to the group by separating the entries with a comma. For example, to add two users to the group, use this format:

  objGroup.PutEx ADS_PROPERTY_APPEND, _      "member", Array("cn=user1,dc=savilltech,dc=com", _         "cn=user2,dc=savilltech,dc=com")  

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.