Pages

Tuesday, August 07, 2007

Active Directory: Copy Distribution List Members to Another Distribution List

Summary: In this example, we will copy all members from one Distribution Group to another Distribution Group.

Copy the contents below and save as copymembers.vbs to C: drive


Const ADS_GROUP_TYPE_GLOBAL_GROUP = &H2

Set objOU = GetObject("LDAP://OU=Security Groups, dc=company, dc=com")
Set objOldGroup = GetObject("LDAP://CN=mysourcegroup, ou=security groups, dc=company, dc=com")
Set objNewGroup = GetObject("LDAP://CN=mytargetgroup, ou=security groups, dc=company, dc=com")

On Error Resume Next
For Each objUser in objOldGroup.Member
objNewGroup.Add "LDAP://" & objUser
Next


Open Command prompt:

C:\>cscript copymembers.vbs


The script will copy all members in the "mysourcegroup" Distribution List to your "mytargetgroup" Distribution List.


Note: Some organizations like to use # in front of their Distribution List names so they appear together in the GAL. Because this is a special character it will need to be in double quotes to treat # as a literal.

Example:
("LDAP://""CN=mysourcegroup""


James Chong (MVP)MCSE M+, S+, MCTS, Security+
msexchangetips.blogspot.com

How useful was this article? Want to see a tip not listed? Please leave a comment.

23 comments:

  1. Anonymous8:52 AM

    I love you!!

    You saved me hours and hours...
    Keep up the good work, I have your blog in my Bookmarks and come back to it constantly

    ReplyDelete
  2. Really useful info, it worked and saved lot of time for me.

    Thanks a lot.

    Regards,
    Maddy

    ReplyDelete
  3. Anonymous1:34 PM

    Thanks a bunch! Exactly the quick script our organization was seeking.

    ReplyDelete
  4. Anonymous1:35 PM

    Thanks a bunch! Exactly the quick script our organization was seeking.

    ReplyDelete
  5. Thank you for posting this!!!!

    ReplyDelete
  6. I'm not able to get the script to work. Not enough information. Need an exampl.

    ReplyDelete
  7. I changed "mysourcegroup" and "mytargetgroup" to the correct group names, but the script fails with this error. What did I miss? Does the script have to be run from the Exchange server? Do any other values in the example have to be changed? Thank you.

    --

    C:\>cscript copy_group.vbs
    Microsoft (R) Windows Script Host Version 5.7
    Copyright (C) Microsoft Corporation. All rights reserved.

    C:\copy_group.vbs(3, 1) (null): A referral was returned from the server.

    ReplyDelete
  8. Anonymous2:40 AM

    This article has saved me alot of time. Thanks!

    ReplyDelete
  9. Anonymous8:02 AM

    I tried the scrip and it runs without error, but does not populate the target group. My groups are universal groups, I am wondering if that matters?

    ReplyDelete
  10. Anonymous2:54 PM

    Thanks.. It works amazing.. awesome

    ReplyDelete
  11. Anonymous7:44 AM

    Thanks for the script, managed to get it working after lots of trial & error.

    Seems the script is very fussy on upper / lower case characters. Also had to create the new distribution list and put it into the correct OU before it would work, and had to make sure that both old and new DL's were global not universal.

    Hope that helps somebody.

    ReplyDelete
  12. Anonymous9:00 AM

    Thank you so much - you saved my day! :-)

    May it is helpful to use add. the MS-Tool ldp (Server support tools) it helps you figure out the right LDAP path information, I had trouble with them first ;-).

    Clear, straight forward help as needed. - Thank you!

    Catta

    ReplyDelete
  13. Anonymous6:23 AM

    Interesting article you got here. I'd like to read a bit more about this matter. Thnx for posting that info.
    Sexy Lady
    Blonde escort

    ReplyDelete
  14. Anonymous1:47 PM

    Capooooooo!!!

    Groso!!!

    Master!!!

    God!!!

    Salvator!!!

    Thanks from Argentina
    C. Castagnola!!!

    ReplyDelete
  15. Thanks for the solution, it works fine

    ReplyDelete
  16. Anonymous9:29 AM

    working brilliant
    thank you

    ReplyDelete