Edit: The inline code in this post is not the latest version of the script. Get the latest version from the downloads page.
It is not uncommon at my company to have to move a user from one domain to another for technical, logistical, or political reasons. For another set of reasons, moving the user account to the other domain is not done, instead manually creating a new one and associating the mailbox with the new account.
DL membership does not automatically get updated when this is done, so I have been doing it manually. It has been on my to-do list for awhile to write a script to copy the DL membership from the old account to the new one. So I threw this together this morning. It lacks some of the nice extras my other scripts have (finding the user by logon name, email results, true logging) but it does work.
You have to edit the script to give it the variables for the old and new users’ dn. It will skip security groups (any group without an alias) and also groups whose Notes (info) attribute contains the word SmartDL. We use Imanami’s SmartDL for automated DL membership when applicable. Those will be automatically updated the next time each of their jobs run.
Download it here, or copy/paste below.
Dim strOldUser, strNewUser, objOldUser, objNewUser, strGroup, objGroup
strOldUser = "" 'dn of user to copy from'
strNewUser = "" 'dn of user to copy to'
Set objOldUser = GetObject("LDAP://" & strOldUser)
Set objNewUser = GetObject("LDAP://" & strNewUser)
wscript.echo "Source user: " & objOldUser.DisplayName
wscript.echo "Target user: " & objNewUser.DisplayName
For Each strGroup in objOldUser.MemberOf
On Error Resume Next
Set objGroup = GetObject("LDAP://" & strGroup)
If Not Trim(objGroup.mailNickname) = "" Then
If Not Instr(objGroup.info, "SmartDL") > 0 Then
If Err.Num = 0 Then
wscript.echo objGroup.DisplayName & ": Update successful."
wscript.echo objGroup.DisplayName & ": Update UNSUCCESSFUL."
wscript.echo objGroup.DisplayName & ": Skipped (SmartDL)."
On Error Goto 0
Set objOldUser = Nothing
Set objNewUser = Nothing