Bulk add users to groups

Welcome Forums General PowerShell Q&A Bulk add users to groups

This topic contains 4 replies, has 2 voices, and was last updated by

1 year, 11 months ago.

  • Author
  • #69486

    Points: 0
    Rank: Member

    Hi Folks

    Relatively new to Powershell and I have Googled this for a while with no solution.

    I am sure it will be basic to some on here.

    I am looking to create a script that utilises a CSV file and allows me to add multiple users to multiple groups.

    So far I have

    Import-Csv "C:\Scripts\ServiceDesk\BulkGroupAdd\BulkGroupAdd.csv" | ForEach-Object {Add-ADGroupMember -Identity $_.GroupName -Members $_.UserName}7

    My csv file headers are


    Using this script I can add users to one group.

    I thought I would be able to add multiple groups into the GroupName field like below


    This fails however and reports that it cannot locate "group1,group2,group3"

    If I just add one group like below the user is added to that group


    I am assuming that something needs to be modified in the actual script.

    If this makes sense could someone very kindly take the time to help?

  • #69498

    Points: 181
    Helping Hand
    Rank: Participant

    ok, you have a bit of a misunderstanding of how add-adgroupmember works.

    add-adgroupmember only touches one ad group at a time.
    you can however add multiple users to the same group with a single call by using a comma seperated list.

    however as add-adgroupmember accepts pipeline input, you might be able to do something like:

    Import-Csv "C:\Scripts\ServiceDesk\BulkGroupAdd\BulkGroupAdd.csv" | ForEach-Object {$_.GroupName|Add-ADGroupMember -Members  $_.UserName}

    i don't have access to a shell at the moment... but you can give that a try

    • #69502

      Points: 0
      Rank: Member

      Thanks David I will give that a try

      So are we saying that its not possible to add multiple users to multiple groups?

      So if I have a spreadsheet with users on it I can't add all of those users to 3 different groups at the one time?

      I would have to run 3 different commands one for each group?

      Apologies if I am not understanding.

    • #69504

      Points: 0
      Rank: Member


      I came across this which is a different approach but seems to be the kind of thing I am looking for.

      Tough learning curve this powershell stuff lol 🙂

  • #69556

    Points: 181
    Helping Hand
    Rank: Participant

    well, another post that was submitted earlier made me aware of a cmdlet i wasn't before.

    Adds a member to one or more Active Directory groups.

    i haven't used it before, but if you look at the post "adding computer to multiple ad groups" there are usage examples there

The topic ‘Bulk add users to groups’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort