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

Viewing 7 reply threads
  • Author
    Posts
    • #174280
      Participant
      Topics: 6
      Replies: 11
      Points: 100
      Rank: Participant

      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.

    • #174298
      Participant
      Topics: 2
      Replies: 1736
      Points: 3,550
      Helping Hand
      Rank: Community Hero

      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.

    • #174316
      Participant
      Topics: 0
      Replies: 115
      Points: 433
      Helping Hand
      Rank: Contributor

      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
         }
      }
    • #174478
      Participant
      Topics: 6
      Replies: 11
      Points: 100
      Rank: Participant

      Hello,

      Thanks for your replay

      i have this so far:

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

       

    • #174481
      Participant
      Topics: 6
      Replies: 11
      Points: 100
      Rank: Participant

      Should i set a value for $Group?

    • #174595
      Participant
      Topics: 0
      Replies: 115
      Points: 433
      Helping Hand
      Rank: Contributor

      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"}

       

       

    • #174616
      Participant
      Topics: 28
      Replies: 59
      Points: 154
      Rank: Participant

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

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

    • #174619
      Participant
      Topics: 0
      Replies: 115
      Points: 433
      Helping Hand
      Rank: Contributor

      John,

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

       

Viewing 7 reply threads
  • The topic ‘Copy AD group members from one to another’ is closed to new replies.