Copy group members from one group to another

Welcome Forums General PowerShell Q&A Copy group members from one group to another

This topic contains 1 reply, has 2 voices, and was last updated by

2 years, 12 months ago.

  • Author
  • #6226

    Points: 0
    Rank: Member

    by james2305 at 2012-12-07 04:24:57


    I imported the ActiveDirectory module and trying to copy all the members from one group to another. Could someone tell me where I am going wrong in my command please

    Get-ADGroupMember "group1" |  % {Add-ADGroupMember "group2" -Members $_}

    I will be honest and say I got the command off an internet page and have tried removing the % and the brackets to no avail.

    Can someone help please

    Many thanks


    by Klaas at 2012-12-07 05:49:50

    Get-ADGroupMember doesn't return the actual user objects, so you have to get-aduser first:
    Get-ADGroupMember "group1" | Get-ADUser | Foreach-Object {Add-ADGroupMember -Identity "group2" -Members $_}

    by RichardSiddaway at 2012-12-07 11:53:48

    Actually you don't need to get the user at all – James' code was almost right.

    This shows how the membership of one group can be copied to another using the Microsoft cmdlets
    $gsource = "GroupUnvlSecA"
    $gtarget = "GroupDmlSecA"
    Get-ADGroupMember -Identity $gsource |
    foreach {
    Add-ADGroupMember -Identity $gtarget -Members $($_.DistinguishedName)

    The differences is that I use the distinguished name property from the group member object to define the user I'm adding into the group. This will throw an error message if the user already exists in the group but will continue

  • #34051

    Points: 0
    Rank: Member

    Thanks a lot RichardSiddaway! This is great:

The topic ‘Copy group members from one group to another’ is closed to new replies.