clear current members of a distrib grp and add new members from a

Discussion in 'Active Directory' started by Phil, May 6, 2008.

  1. Phil

    Phil Guest

    2003 AD, Native forest and Domain.
    XP SP2 clients.

    I need to script up a way of clearing all current members for an AD
    Distribution Group and then adding back in all the members from a .txt or
    ..csv file.

    The script needs to be able to be run by users that have permissions to the
    AD group object.

    Any ideas?
     
    Phil, May 6, 2008
    #1
    1. Advertisements

  2. ## Clear the group ##

    Set objGroup = GetObject
    ("LDAP://cn=GroupName,ou=SomeOU,dc=domainName,dc=com")

    objGroup.PutEx ADS_PROPERTY_CLEAR, "member", 0

    objGroup.SetInfo



    ## Add user to the group ##

    Set objGroup = GetObject _

    ("LDAP://cn=GroupName,ou=SomeOU,dc=domainName,dc=com")

    objGroup.PutEx ADS_PROPERTY_APPEND, "member", Array(DistinguishedName)

    objGroup.SetInfo


    This should all be available at:
    http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx?mfr=true
     
    Paul Bergson [MVP-DS], May 6, 2008
    #2
    1. Advertisements

  3. Phil

    Phil Guest

    Thanks Paul.

    In the ## Add user to the group ## section, how do I get it to read the list
    of users to be added to the group in from a .txt or .csv file etc.

    Phil
     
    Phil, May 7, 2008
    #3
  4. If you go to the script center from the link I provided you should be able
    to find examples on reading a text file.
     
    Paul Bergson [MVP-DS], May 7, 2008
    #4
  5. Jorge de Almeida Pinto [MVP - DS], May 20, 2008
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.