Copy AD group members from one to another

Hello,

I have a command to copy AD group members from one to another
but i want to do that with the help of Excel file for multiple groups.
i want PowerShell to get the content of column A (old group name) and copy all the members to the new group (column B).
internet search didn’t help for me.

Thanks.

We’re used to be better when we get something to tweak. What do you have so far? Please show your code. Powershell.org is not a free code writing service – you know that, right? We expect you to do your own research before and at least try to solve your problem by yourself.

Atx750K,

Olaf is right without having any code to work with we can’t really assist much further. Below is an example of how I would go about it. Note the Headers in the csv file would be OldGroup and NewGroup.

ForEach ($Group in (Import-Csv C:\Temp\GroupAssignment.csv)){
   $OldGroupMembership = Get-ADGroupMembership -Identity $Group.OldGroup
   If ($null -ne $OldGroupmembership){
      Add-ADGroupMembership -Identity $Group.NewGroup -Members $OldeGroupMembership
   }
}

Hello,

Thanks for your replay

i have this so far:

Add-ADGroupMember -Identity 'New Group' -Members (Get-ADGroupMember -Identity 'Old Group' -Recursive)

 

[quote quote=174316][/quote]

Should i set a value for $Group?

Atx750K,

When you use the foreach loop you have to assign a variable to the item that is being iterated through, it can be called anything you want. Here is another example.

$Pizza = Get-Content C:\temp\Pepperoni.txt

Foreach ($Slice in $Pizza){
   Write-Output "I ate $slice"}

 

 

@jason.robertson as much as I prefer the spelling “olde”, you do only use it one out of three times in your script. :slight_smile:

Add-ADGroupMembership -Identity $Group.NewGroup -Members $OldeGroupMembership

John,

Hahaha yeah, thankfully tab complete is our friend. :slight_smile: We can chalk it up to using mid 19th century English instead of modern English. :wink: