Copy the users from a ADgroup to another ADgroup
To Copy the users from a ADgroup to another ADgroup or duplicate the contents of a group, us the commandlet Add-ADGroupMember.
You cannot pipe the contents of Get-ADGroupMember to this commandlet as it does not accept pipeline imput. You can check this in the help of the command.
1 2 3 4 5 6 7 8 9 |
PS C:\> get-help Add-ADGroupMember -Parameter members .... You cannot pass objects through the pipeline to this parameter. Required? true Position? 2 Default value Accept pipeline input? false Accept wildcard characters? false |
For this to work correctly you must place the content in a variable with Get-ADGroupMember and use this in Add-ADGroupMember.
These two command are:
1 2 3 |
PS C:\>$members = Get-ADGroupMember "SourceGroupName" PS C:\> foreach ($i in $members){Add-ADGroupMember -Identity "DestinationGroupName -Members $i} |