add user to active directory group ADGroupMember

Add User to Active Directory Group Using Add-ADGroupMember

The Active Directory Module for Windows PowerShell includes the Add-ADGroupMember cmdlet, which can be used to add user to Active Directory security or distribution groups. In order to use cmdlets from the ActiveDirectory module, at first you must load this module into your PowerShell session (on domain controllers with Windows Server 2012 or higher, this module is automatically loaded):

Import-Module ActiveDirectory

To add user1 to the domain group “TestGroup1”, run the following command in the PowerShell console with administrator privileges:

Add-ADGroupMember "TestGroup1" user1

Add ADGroupMember

You can add several users to the group at once, their accounts should be enumerated by comma:

Add-ADGroupMember "NYTraders" KDunkelman,SSmith

These are the simplest examples of using the Add-ADGroupMember cmdlet to add users to AD groups. Let’s consider some more complex methods.

For example, you need to get a list of users of one group (NYTraders) and add these accounts to another AD group (USTraders). To obtain a list of users of the NYTraders group, we will use the Get-ADGroupMember cmdlet. The resulting command might look like this:

Get-ADGroupMember “NYTraders” | Get-ADUser | ForEach-Object {Add-ADGroupMember -Identity “USTraders” -Members $_}

You can add to the group all users from a particular OU:

Get-ADUser -Filter * -SearchBase ‘OU=Users,OU=NY,OU=USA,DC=theitbros,DC=com’|

ForEach-Object -process {Add-ADGroupMember -identity "NY Users" -Members $_.SamAccountName}

After executing the command, you can open the ADUC console and make sure that all users have been added to the specified group.

Add_ADGroupMember identity

You can select users based on the value of some AD attribute and then add them to the particular group. For example, to add all users to the USAUsers group that have the United States in the co field, run the command:

Get-ADUser -filter {(co -eq "United States")} | ForEach-Object -process {Add-ADGroupMember -identity "USAUsers" -Members $_.SamAccountName}

You can create an Excel file (or a text CSV file) with a list of users that you want to add to a specific AD group. The file should be a list of samAccountNames of your users. You can use the following file format:

add user to active directory group

Below is the code of PowerShell script for adding users from CSV to the group:

$List = Import-CSV .\users.csv



ForEach ($User in $List)


Add-ADGroupMember -Identity ‘USTraders’ -Member $User.username


if ($error.Count -gt 0)


echo "Errors count: " $error.Count



if ($success -gt -1)


echo $success " users added successfully"


Similarly, you can add users to the Exchange distribution group:

Import-CSV .\Users.csv | ForEach-Object -process {Add-DistributionGroupMember -Identity "USTradersMailList" -Member $_.username }

You may also like:

How to transfer FSMO Roles From a Failed Domain Co... In case domain controller, which owns FSMO (Flexible Single Master Operation) roles, is fail (virus attack, fatal software problems or catastrophic ha...
AD Account Keeps Locking Out Sometimes there are situations when AD account keeps locking out, this happen when you try to log on to a domain computer and getting an error on the ...
Installing Active Directory Users and Computers MM... One of the main Active Directory domain management tools is the MMC snap-in Active Directory Users and Computers (ADUC). The ADUC snap-in is used to p...
Store BitLocker Recovery Keys using Active Directo... In a domain network, you can store the BitLocker recovery keys for encrypted drives in the Active Directory Domain Services (AD DS). This is one of th...
Fix: Active Directory Domain Controller Could Not ... In this article, we’ll take a look at why it’s not possible to join a new computer to the Active Directory domain with an error Active Directory Domai...

Add Your Comment