Add-AdGroupMember – Add Users to AD Groups

Add user accounts to Active directory groups in large organizations really a time-consuming task if you do it using a manual way. In PowerShell, you can add users to AD groups using ADUC (Active Directory Users and Computers) or add users to AD groups using PowerShell Add-ADGroupMember cmdlet.

PowerShell Add-ADGroupMember cmdlet in Active Directory adds users, computers, service accounts, or groups to active directory groups. We will use the Add-AdGroupMember cmdlet to add user accounts to AD Groups or bulk add users to AD groups.

In this article, I will explain both ways to add users to active directory groups using ADUC and PowerShell Add-ADGroupMember active directory cmdlet.

Active Directory Users and Computers (ADUC) graphical user interface tool used to add users through AdGroup MemberOf properties.

Let’s understand ADUC and Add-ADGroupMember cmdlet in detail to add users to ad groups in the active directory with example.

Add User to AD Groups using ADUC

In this example, we will use the Active Directory Users and Computers (ADUC) GUI tool to add users to the Security Group.

For example, I have created a Finance Security Group in the active directory. We will add ad user Esh to Security group using ADUC.

To add user accounts to security groups in the active directory using ADUC, follow the below steps

  1. Open ADUC ( Active Directory Users and Computers)

Go to Start –> Run –> dsa.msc –> click OK

type dsa.msc command in the Run dialog and click Ok to open the ADUC GUI console.

2. Navigate to Organizational Unit in your domain where you have security groups and users created.

Refer to the below image, where Finance is a security group and Esh Deol is an active directory user.

ADUC - Security Groups in Active Directory
ADUC – Security Groups in Active Directory

3. Right Click on User

Right-click on the user ( Esh Deol) and select Properties menu to open Properties dialog and select MemeberOf properties as given below in the image

ADUser MemberOf Property
ADUser MemberOf Property

4. Click on Add button to open Select Groups Dialog

type the AD group name in the search textbox and click on Check Names to check ad group name availability in active directory, if available it will return ad group else will give the message.

Select AD Group for AdUser
Select AD Group for AdUser

Click on the OK button to return. You can use the Advanced button to search for group names visually in an active directory and use a filter to select AD group.

5. Security ADGroup added to User MemberOf property, click apply to save changes as below

ADUser MemberOf Security ADGroup
ADUser MemberOf Security ADGroup

6. It will successfully add a user account to AD groups. If you want to check user added or not, open security adgroup and check member properties as below

Security ADGroup aduser
Security ADGroup aduser

Cool Tip: How to add a computer to a group using Add-AdGroupMember

Add-ADGroupMember to Add Users to AD Group

If you want to add users to the ad groups using PowerShell, use Add-ADGroupMember active directory cmdlet.

Let’s consider an example to add a user account to Security AD Group using Add-ADGroupMember as below

ADUser Name : Tira Elsa

Security AdGroupName: Finance

Add-ADGroupMember -Identity Finance -Members Tira.Elsa

In the above PowerShell script, Add-AdGroupMember active directory cmdlet adds a user account to the security adgroup specified by Identity parameter and user-specified by Members property.

You can verify the user added to a group or not using the Get-ADPrincipalGroupMembership cmdlet as below

Get-ADPrincipalGroupMembership -Identity Tira.Elsa

Get-Get-ADPrincipalGroupMembership return adgroup information for aduser specified by Identity parameter.

The output of the above command to add a user account to adgroup in PowerShell as below

Add User Accounts to AD Groups - PowerShell
Add User Accounts to AD Groups – PowerShell

Cool Tip: How to get-aduser employee id in PowerShell!

Bulk Add Users to AD Groups in PowerShell

If you want to bulk add user accounts to AD groups in PowerShell, you can do it using Add-ADGroupMember cmdlet in the active directory.

Let’s consider an example where you have user names in the CSV file. You can import CSV file in PowerShell scripts and load users in a local variable as below

# Script for bulk add users to ad groups
#Import csv file and loads adusers in variable

$Users = Import-Csv -Path "C:\adusers.csv"

#Iterate AdUsers to add user account in Group

foreach($User in $Users){
        try
        {

            Add-ADGroupMember -Identity Finance -Members $User.User -ErrorAction Stop -Verbose
        }
        catch
        {
            Write-Host "Error while adding user to adgroup"
        }

    }

In the above PowerShell script,

Import CSV file having Username and store information in $Users variable.

Iterate $Users using Foreach and user Add-AdGroupMember cmdlet to add a user to adgroup specified by Identity parameter and user-specified by Member parameter.

It will bulk add user accounts to ad groups.

The output of bulk add user accounts to ad groups as below

Bulk add user accounts to adgroup
Bulk add user accounts to adgroup

Cool Tip: How to find an operating system of an adcomputer in PowerShell!

Conclusion

I hope the above article to add users to ad groups is helpful to you. You can use ADUC and Add-ADGroupMember PowerShell cmdlet to add a user account.

To bulk add users to the security adgroup use Add-AdGroupMember cmdlet to add users one by one using a foreach loop in PowerShell.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Leave a Comment