PowerShell script to copy members from one group to another

If you like me sometimes need to copy users and/or computers from one group to another this script will help you.

Just save the script (to for example “CopyGroupMembers.ps1”) and run it like “CopyGroupMembers.ps1 -FromGroup <groupname> -ToGroup <groupname>” by using the parameters to copy the group members.

To get the script to work you need the Active Directory PowerShell module installed where you run the script and security rights to copy the members.

Param(
    [Parameter(Mandatory=$True)]
    [String]$FromGroup,
    [Parameter(Mandatory=$True)]
    [String]$ToGroup
)
Process
{
    Import-Module ActiveDirectory
    $FromGroupMembers = Get-ADGroupMember -Identity $FromGroup
    Foreach ($Member in $FromGroupMembers.distinguishedName)
    {
        Add-ADGroupMember -Identity $ToGroup -Members $Member
       Write-Host “Added member: $Member to group $ToGroup
   }
}

One Response to PowerShell script to copy members from one group to another

  1. Razvan November 10, 2015 at 16:38 #

    good script – some additional info for new users:

    save script exactly as it is at c:\users\YourUsername

    open PowerShell

    type: .\CopyGroupMembers.ps1 -FromGroup test -ToGroup test2

    where
    test = source group
    test2 = destination group

Leave a Reply