Adding multiple users in the same OU is easy task, only you need to select users and add them to multiple groups. The Biggest challenges is when adding users from multiple OU’s in multiple groups.

In this blog, We will learn to add multiple users from different ou’s into multiple AD groups.

We have created a CSV file in which Active Directory users(sAMAccountName) and group names are written and this CSV file will be called in powershell script.

Run the Below powershell script on any domain controller, member server or a client machine  with delegated rights or domain admin account.

# Start transcript
# Import active directory module for running AD cmdlets
Import-module ActiveDirectory

#Store the data from UserList.csv in the $List variable
$List = Import-CSV .\UserList.csv

#Loop through user in the CSV
ForEach ($User in $List)
{

#Add the user to the TestGroup1 group in AD
Add-ADGroupMember $User.Group -Members $User.User -ErrorAction Stop -Verbose
}


By amit_g

Welcome to my IT Infra Blog! My name is Amit Kumar, and I am an IT infrastructure expert with over 11 years of experience in the field. Throughout my career, I have worked with a wide variety of systems and technologies, from network infrastructure and cloud computing to hardware and software development. On this blog, I aim to share my knowledge, insights, and opinions on all things related to IT infrastructure. From industry trends and best practices to tips and tricks for managing complex systems, my goal is to provide valuable information that will help IT professionals and enthusiasts alike. Whether you are a seasoned IT veteran or just getting started in the field, I hope you will find my blog to be a valuable resource. In addition to sharing my own thoughts and ideas, I also welcome feedback, comments, and questions from my readers. I believe that a collaborative approach is the best way to advance the field of IT infrastructure and I look forward to hearing from you. Thank you for visiting my blog, and I hope you will continue to follow along as I explore the fascinating world of IT infrastructure. Sincerely, Amit Kumar

One thought on “Add users to multiple groups with PowerShell”
  1. How would i go about adding a delimiter to the script to seperate multiple groups to a single user?

    For example:

    User,Group
    eng1,FinanceRO and Finance RW
    eng2,FinanceRO and Helpdesk and infra_ops
    etc…

    Thanks!

Leave a Reply

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