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

John Savill

October 24, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today

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    
objGroup.setInfo  

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")  

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like