How to Use New-MgGroupMember to Add Microsoft 365 Group Members?

Adding users to Microsoft 365 groups is a common administrative task—especially when managing large teams, projects, or distribution lists. Thankfully, Microsoft Graph PowerShell provides an efficient cmdlet to automate this: New-MgGroupMember.

In this guide, we’ll explore how to use the New-MgGroupMember cmdlet, walk through real-world examples, and highlight when and why this cmdlet comes in handy.


What is New-MgGroupMember?

New-MgGroupMember is a Microsoft Graph PowerShell cmdlet used to add a member to a Microsoft 365 group. The member must be represented as a directory object (typically a user), and the target group is identified by its unique Group ID.

This cmdlet allows you to add:

  • Users to security groups
  • Members to Microsoft 365 groups
  • Members to distribution lists (if backed by Microsoft 365)

Why Use New-MgGroupMember?

  • Automate user onboarding – Add new employees to required groups with a script.
  • Handle bulk assignments – Add multiple users to a group quickly.
  • Simplify administration – Especially useful when paired with CSV input for batch processing.
  • Ensure consistency – Avoid manual errors by using code-based group assignments.

Cmdlet Syntax

New-MgGroupMember -GroupId <String> -DirectoryObjectId <String>

Parameters:

  • -GroupId: The unique identifier (GUID) of the Microsoft 365 group.
  • -DirectoryObjectId: The object ID of the user (or other directory object) to add as a member.

Usage Examples

Example 1: Add a user to a group

$groupId = "d9f6b5c5-67e5-41d1-9af0-8c85b6f15d0c"
$userId = "5c5d5f65-1d6b-4141-a5e5-b8c85d0c6e8f"
                                                                            
try {
    New-MgGroupMember -GroupId $groupId -DirectoryObjectId $userId
    Write-Host "User with ID $userId has been successfully added to the group with ID $groupId." -ForegroundColor Green
} catch {
    Write-Host "Failed to add user to the group. Error: $_" -ForegroundColor Red
}

Example 2: Add multiple users to a group

$groupId = "d9f6b5c5-67e5-41d1-9af0-8c85b6f15d0c"
$userIds = @("5c5d5f65-1d6b-4141-a5e5-b8c85d0c6e8f", "6d7e8f70-6e7b-41d2-a6f7-9c85d7f16e9d")
foreach ($userId in $userIds) {
    try {
        New-MgGroupMember -GroupId $groupId -DirectoryObjectId $userId
        Write-Host "User with ID $userId successfully added to the group with ID $groupId." -ForegroundColor Green
    } catch {
        Write-Host "Failed to add user with ID $userId to the group. Error: $_" -ForegroundColor Red
    }
}

Example 3: Add members from a CSV file

$csvPath = "C:\path\to\your\members.csv"
$members = Import-Csv -Path $csvPath
                                            
foreach ($member in $members) {
    $user = Get-MgUser -UserPrincipalName $member.UserPrincipalName
    New-MgGroupMember -GroupId $member.GroupId -DirectoryObjectId $user.Id
}

CSV file format

Make sure your CSV file is structured like this:

UserPrincipalName,GroupId
user1@domain.com,d9f6b5c5-67e5-41d1-9af0-8c85b6f15d0c
user2@domain.com,d9f6b5c5-67e5-41d1-9af0-8c85b6f15d0c

Frequently Asked Questions


Can I add guest users to a group using this cmdlet?

Yes, as long as the guest user already exists in Azure AD. Otherwise, invite them first using New-MgInvitation.


Will this cmdlet work for security groups and Microsoft 365 groups?

Absolutely. You just need the correct GroupId and a valid user DirectoryObjectId.


What if a user is already a member of the group?

The cmdlet will return an error like “One or more added object references already exist”. You can ignore it or handle it in your script.


Use Cases

  • New Hire Onboarding: Automatically add new employees to department-specific Microsoft 365 groups.
  • Group Membership Updates: sync group membership with an external HR system using scheduled scripts.
  • Project-Based Assignments: Quickly add users to ad-hoc project groups without manual steps.

Conclusion

The New-MgGroupMember cmdlet is a must-have for every Microsoft 365 admin's toolbox. Whether you're managing one group or a hundred, automating group memberships can save hours of manual work and ensure your organization runs smoothly.

Pro Tip: Always double-check the GroupId and DirectoryObjectId before adding members to avoid errors or duplication.

Have you tried using New-MgGroupMember in your admin routine? Let us know how it helped simplify your tasks!


Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.

Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.

© Your Site Name. All Rights Reserved. Design by HTML Codex