Command to Copy Member Of from one Group to another AD Group

By | December 19, 2016

Have googled this and didn’t found command/script to copy member of, however found many articles to copy members from a group, though of write a simplified command to achieve this, have already discussed how to copy group membership from one group to another group

Also Read: Display the list of members with nested groups

Source Group = accounts (Old Group)

Destination Group = Test (New group)

How to copy Active Directory Group member of from one user to another

Unlike the group membership, there is no simple and straight forward method to copy group member of from an AD Group, have found a way to do this

Step 1: To get member of from an accounts group

dsget group  "CN=accounts,OU=Groups,DC=windowstricks,DC=in" –memberof >>c:\temp\accounts.txt

or

dsquery group -name acciunts |dsget group –memberof >>c:\temp\accounts.txt

Step2: Add test group to list of member of Groups

For /f "tokens=1-3 delims=;" %a in (c:\temp\accounts.txt) do dsmod group  %a  -addmbr "CN=test,OU=Groups,DC=windowstricks,DC=in"

Seems to be simple, How about bulk copy like this for many source and destination groups

Also Read: To get the members status from the active directory group

How to Copy Active Directory Group member of from bulk list of groups

Have to create input file, update the input file like below and save to list.txt on c:\temp

SourceGroupName;destinationgroupDN;

Example:

accounts;”CN=test,OU=Groups,DC=windowstricks,DC=in”;

To Find distinguished name (LDAP path for the object)

Command Copy Active Directory Group member of from bulk list of groups

For /f "tokens=1-3 delims=;" %a in (c:\temp\list.txt) do dsquery group -name %a | dsget group -memberof >>c:\temp\%a.txt && for /f "token=1-3 delims=;" %d in (%a.txt) do dsmod group %d -addmbr %b

Hope this will help you to save time by executing above command to add a same list of members of from a one AD group to another

Also Read: Simple Oneline Script to save Admin work

 

Leave a Reply

Your email address will not be published. Required fields are marked *