LiquidObject

Outlook and 5.4.4 Routing Errors »« Bad Fragmentation

Using PowerShell to copy Active Directory Group Membership

If you’ve ever needed to group membership between to AD groups you could do this one by one which while does work, what happens if you have a list with 10, 20, 30,….or even 5000+ users? To copy the membership from one group into another via PowerShell under Server 2008 is a simple two lines (plus import command).

 


Import-Module ActiveDirectory

$mymembers = Get-ADGroupMember -identity My_Source_Group_Name | Select-Object SamAccountName

foreach($i in $mymembers){Add-ADGroupMember -Identity My_Destination_Group_Name -Members $i.SamAccountName}
, ,
November 18, 2011 at 11:35 am
2 comments »
  • February 21, 2013 at 3:32 pmPaul

    Worked great for me! Any chance you can show how to add users from different child domains to the top level domain group. Your script fails if the username is not found in the same domain as the group created.

  • March 3, 2013 at 9:01 pmPatrick

    If using child domains you can used the DistinguishedName attribute instead of SamAccountName. Depending upon your topology, you may need to wrap the Add-ADGroupMember method with some string matching against the end of the DistinguishedName.

Leave a Reply or trackback