0
0
PowershellHow-ToBeginner · 3 min read

How to Add User to AD Group with PowerShell

Use the Add-ADGroupMember cmdlet in PowerShell to add a user to an Active Directory group. Specify the group name with -Identity and the user with -Members. For example: Add-ADGroupMember -Identity "GroupName" -Members "UserName".
📐

Syntax

The basic syntax to add a user to an AD group is:

  • Add-ADGroupMember: The command to add members to a group.
  • -Identity: Specifies the AD group name or distinguished name.
  • -Members: Specifies the user(s) to add by username, distinguished name, or object GUID.
powershell
Add-ADGroupMember -Identity "GroupName" -Members "UserName"
💻

Example

This example adds the user jdoe to the AD group SalesTeam. It assumes you have the Active Directory module imported and the necessary permissions.

powershell
Import-Module ActiveDirectory
Add-ADGroupMember -Identity "SalesTeam" -Members "jdoe"
Write-Output "User jdoe added to SalesTeam group."
Output
User jdoe added to SalesTeam group.
⚠️

Common Pitfalls

Common mistakes when adding users to AD groups include:

  • Not running PowerShell as an administrator or without proper permissions.
  • Using incorrect group or user names (case-sensitive or misspelled).
  • Not importing the Active Directory module before running the command.
  • Trying to add a user who is already a member (no error but no change).

Always verify group and user names with Get-ADGroup and Get-ADUser before adding.

powershell
## Wrong: Missing module import
Add-ADGroupMember -Identity "SalesTeam" -Members "jdoe"

## Right: Import module first
Import-Module ActiveDirectory
Add-ADGroupMember -Identity "SalesTeam" -Members "jdoe"
📊

Quick Reference

ParameterDescription
-IdentityName or distinguished name of the AD group
-MembersUser(s) to add (username, DN, or GUID)
-ConfirmPrompts for confirmation before adding
-WhatIfShows what would happen without making changes

Key Takeaways

Use Add-ADGroupMember with -Identity for the group and -Members for the user.
Always import the Active Directory module before running the command.
Run PowerShell with proper permissions to modify AD groups.
Verify user and group names to avoid errors.
Use -WhatIf to test commands safely before applying changes.