Powershell – AD – Add users to groups from list

As an admin you will often be given a list of users that need to be added to a certain AD certain security group. This post will show you how to perform this task.


  1. The content of the user list should be in the below formatuserlist
  2. The Active Directory Module will be required. You can install that by following this post.

Code description

  1. The $UserNamesList variable will be populated with the content of the text file
  2. The script will iterate through the list and add each username to the group if it is able to


$userNamesList = get-content -path "C:\temp\users.txt"

foreach ($userName in $userNamesList){

(Add-ADGroupMember -Identity TestGroup -Member $userName)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s