In my quest to learn more about PowerShell, I’ve learned how to add a user to an AD group with a single command. There are a lot of powerful scripts that can automate the process even more, however I’m writing this simple one liner to show how to simply add users to groups with the AD module in PowerShell.

Step 1: Import the AD Module

7d7da82e93c00c07553d76cf0ebadec51c0e41784a0f8a7991abef592233716d_2013-09-18_11h10_35.png

Use the Import-Module ActiveDirectory command to gain access to AD commands in your PowerShell Prompt.

C:>Import-Module ActiveDirectory

Step 2: Add the User to the Group

Issue the below command to add a user as a member to a group

C:>Add-ADGroupMember -Identity “GroupNAME” -Member USERNAME

Step 3: Confirm the User Was Added

To check and make sure the user was actually added to the group there is another simple command as seen below.

C:>Get-ADGroupMember “GroupNAME”

11 Spice ups

The parameter -member is wrong.

It has to be -members even if it’s only one user to add.

Awesome tutorial, very practical application.

In order to add a user to multiple groups; would we just need to separate the groups with commas?

This was awesome Thanks! I also had to change -member to -members.

I have like 200 employees I need to add, is there a way to do that with a variation of this? Maybe running off of a CSV file?

$csv = Import-Csv -Path “c:\scripts\members.csv”

ForEach ($item In $csv)
{
$Add_group = Add-ADGroupMember -Identity $item.GroupName -Members $item.Membername
Write-Host -ForegroundColor Green “Group $($item.GroupName) modified!”
}

Groupname and Membername would be the header of your CSV file.

Ryan0527

Can you please provide an example of how the .csv file should look?