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

Author: PeteLong

Share This Post On

Submit a Comment

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