PowerShell: Bulk Add/Remove Users From Groups

KB ID 0001475


I had to do this a few weeks ago, so I documented it. I had a list of usernames in a CSV file and I needed to bulk-add them to a security group.

Bulk Add Group Users Solution

Firstly you will need the usernames (sAMAccountNames) in .csv format like so,  (Note: As a header Im using User-Name.) I’ve saved the file to C:\Temp on my server.

User Name CSV

Execute the following commands;

Import-Module ActiveDirectory 

Import-Csv -Path “C:\Temp\Users-To-Add.csv” | ForEach-Object {Add-ADGroupMember -Identity “Group-Name” -Member $_.’User-Name’}

Bulk add Users to Group

And there’s our users;

Bulk add Users from CSV

Bulk Remove Group Users Solution

Use the following command;

Import-Csv -Path “C:\Temp\Users-To-Remove.csv” | ForEach-Object {Remove-ADGroupMember -Identity “Group-Name” -Member $_.’User-Name’ -Confirm:$false}

Bulk remove Users from a Group

Now if we check the group, the users have gone;

Bulk remove Users from group with CSV

Related Articles, References, Credits, or External Links

PowerShell: Bulk Enable / Disable Users

Exchange Bulk Export / Import Mail Contacts

Bulk Export Users From One Domain, and Import Into Another

PowerShell: Add All Members of an OU to a Security Group

Author: PeteLong

Share This Post On


  1. What if i wanted to add users to multiple groups . For example if i had a list of sam account names and they needed to be addedd to multiple groups

    Post a Reply
    • Hi,
      Assuming you have Groups in a column called ‘Group’, and Users in a column called ‘User-Name’;

      $list = import-csv “C:\Folder\Input-File.csv”

      Foreach($user in $list){
      add-adgroupmember -identity $user.Group -member (Get-ADUser $user.User-Name)


      Post a Reply
  2. I’m trying to do something similar. I have a list of AD groups I would like to remove all users from. I can do them individually, but can’t seem to get the format down to import a txt/cvs list of the groups, and then delete all the users from those groups. Any help would be appreciated.

    Post a Reply

Submit a Comment

Your email address will not be published. Required fields are marked *