Copy members to a group

Discussion in 'Active Directory' started by Diane Walker, Dec 19, 2008.

  1. Diane Walker

    Diane Walker Guest

    We are running Active Directory on Windows 2003 server. Is there a way to
    copy all the users in one group to another existing group or a new group?
    This one particular group has more than 50 users and I don't want to
    manually type the name of the each user.

    Thanks.
     
    Diane Walker, Dec 19, 2008
    #1
    1. Advertisements

  2. Probably can be done with command line utilities, but I prefer to script it.
    In VBScript:
    =========
    ' Bind to source group.
    Set objSource = GetObject("LDAP://cn=Sales,ou=West,dc=MyDomain,dc=com")

    ' Bind to target group.
    Set objTarget = GetObject("LDAP://cn=Marketing,ou=West,dc=MyDomain,dc=com")

    ' Enumerate direct members of source group.
    For Each objMember In objSource.Members
    ' Check if this object already a member of the target group.
    If (objTarget.IsMember(objMember.AdsPath) = False) Then
    ' Add this object to the target group.
    objTarget.Add(objMember.AdsPath)
    End If
    Next
    =========
    I'm not sure any command line utility can handle the possibility that
    someone is already a member of both groups.
     
    Richard Mueller [MVP], Dec 19, 2008
    #2
    1. Advertisements

  3. Diane Walker

    Diane Walker Guest

    Thanks very much for your prompt response and assistance, Richard.
     
    Diane Walker, Dec 19, 2008
    #3
  4. Diane Walker

    Diane Walker Guest

    Richard,

    Your script works perfectly!!! You have saved me hours of work in the past.
    You saved me hours of work again today. Thanks so much again for taking
    time to write this script.
     
    Diane Walker, Dec 19, 2008
    #4
  5. Glad to help.

    Richard

     
    Richard Mueller [MVP], Dec 19, 2008
    #5
  6. one line ... ;-)

    dsget group "CNofGroup" -members | dsmod group "CNofGroup" -addmbr

    Mark
     
    Mark Heitbrink [MVP], Dec 20, 2008
    #6
  7. That works. Is there a way to get it to work when one or more objects is
    already a member of both groups?
     
    Richard Mueller [MVP], Dec 20, 2008
    #7
  8. Hi,
    You mean, how to supress the abortion if an error is detected?
    dsmod group /? -> -c

    dsget group "CNofGroup" -members | dsmod group "CNofGroup" -addmbr -c

    Mark
     
    Mark Heitbrink [MVP], Dec 21, 2008
    #8
  9. Diane Walker

    Diane Walker Guest

    Thanks.

     
    Diane Walker, Dec 22, 2008
    #9
  10. Diane Walker

    brain007

    Joined:
    Apr 19, 2011
    Messages:
    13
    Likes Received:
    0
    brain007, Apr 19, 2011
    #10
    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.