Friday, 14 February 2014

Copy users from one AD group to another

Are you tried to switch the AD groups?
If yes you probably encounter a problem with how to copy all users from one group to another.
I found easy vbs script for doing this on the Technet here .
Please remember that this is not my work, but I'm using it and checked that it's working correctly.
First, you need to enter object source in the format of CN, OU, DC,DC, for example CN=group, OU=Atlanta, OU=Company, DC=contoso, DC=com.
Then you'll need to do the same with the destination group.
Here is the script:

strSGroupDN = InputBox ("Enter the DN of Source Group" & VBCRLF &_
                  vbcrlf& _
                  vbcrlf& _
                  "e.g. CN=Source Group,OU=Users,DC=NWTraders,DC=com")
strDGroupDN = InputBox ("Enter the DN of Destination Group" & VBCRLF &_
                  vbcrlf& _
                  vbcrlf& _
                  "e.g. CN=Destination Group,OU=Users,DC=NWTraders,DC=com")

set dicSeenGroupMember = CreateObject("Scripting.Dictionary")
set objDGroup = GetObject("LDAP://" & strDGroupDN)

DisplayMembers "LDAP://" & strSGroupDN, dicSeenGroupMember
Function DisplayMembers (strGroupADsPath, dicSeenGroupMember)
   set objGroup = GetObject(strGroupADsPath)
   for each objMember In objGroup.Members
       objDGroup.Add("LDAP://" & objMember.distinguishedName)
    next
End Function

MsgBox "Group Members have been copied to Destination Group"

No comments:

Post a Comment