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

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.

Frequently Asked Questions

  • What is New-MgGroupMember?
    New-MgGroupMember is a Microsoft Graph PowerShell cmdlet that allows administrators to add users or service principals to a group in Microsoft 365. This cmdlet supports adding members to security groups and Microsoft Teams groups.
  • Can I use New-MgGroupMember to add guest users to a group?
    Yes, you can use New-MgGroupMember to add guest users to a group. However, ensure the guest user is already added to the tenant, and you have their Object ID or UserPrincipalName for the operation.
  • Can I use email addresses instead of object IDs to add members?
    No. The -DirectoryObjectId parameter strictly requires the Azure AD object ID of the user. You’ll need to resolve the user’s ID using a separate Get-MgUser call like:
    (Get-MgUser -UserId "user@domain.com").Id
  • Does this cmdlet work for Microsoft 365 Groups and Security Groups?
    Yes. New-MgGroupMember can be used to add members to both Microsoft 365 Groups and Azure AD Security Groups. However, for Microsoft Teams, make sure the group is team-enabled, or use Add-MgTeamMember for role-specific membership (like owner/member).
  • How to verify group membership after adding users to the group?
    Run Get-MgGroupMember -GroupId $groupId command. This should list the User Id of the user(s) you just added to the group.
🔁 Group Memberships Aren’t Instant — Use Delay for Validation

When automating group assignments with New-MgGroupMember, the membership may not reflect immediately due to backend processing.

To verify new memberships reliably (especially in automation scripts), introduce a short delay or loop-check before calling Get-MgGroupMember.
🔐 @odata.id Must Follow Microsoft Graph Format

When adding a member using New-MgGroupMemberByRef, you must pass the object reference in the correct Microsoft Graph format:

https://graph.microsoft.com/v1.0/directoryObjects/{ObjectId}
Passing just the Object ID or UPN will result in errors. This format ensures the API can properly locate and bind the member object.
💡 Groups Can Include More Than Just Users

Azure AD groups can include a variety of object types as members. With New-MgGroupMemberByRef, you can add:
  • Users — via Get-MgUser
  • Service Principals — via Get-MgServicePrincipal
  • Devices — via Get-MgDevice
  • Other Groups — for nested group membership
Just ensure you're using the correct Object ID and API path in your @odata.id reference.

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