New-MgGroupMemberByRef is a Microsoft Graph PowerShell cmdlet used to add directory objects (typically users) as members of a Microsoft 365 or security group by reference. It posts the member’s object ID to the group’s members collection.
Try the M365Corner Microsoft 365 Reporting Tool — your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.
Admins use this cmdlet to automate group membership management at scale. It’s ideal for bulk onboarding, project-based access changes, licensing workflows, and scheduled audits—without manual clicks in the admin center. Because it works with object references, it’s fast, script-friendly, and dependable for large tenants.
Make sure you’re connected to Graph with write permissions for groups:
Install-Module Microsoft.Graph -Scope CurrentUserConnect-MgGraph -Scopes "Group.ReadWrite.All" Basic syntax:
New-MgGroupMemberByRef -GroupId <String> -BodyParameter <Hashtable>
You pass the target GroupId and a hashtable containing the member’s @odata.id (directoryObject URL). Use it for single additions, loops, or CSV-driven bulk updates.
$NewMember = @{
"@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/12345678-90ab-cdef-1234-567890abcdef"
}
New-MgGroupMemberByRef -GroupId "87654321-fedc-ba98-7654-3210fedcba98" -BodyParameter $NewMember
$Members = @(
@{
"@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/12345678-90ab-cdef-1234-567890abcdef"
}
@{
"@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/23456789-0abc-def1-2345-67890abcdef1"
}
)
foreach ($Member in $Members) {
New-MgGroupMemberByRef -GroupId "87654321-fedc-ba98-7654-3210fedcba98" -BodyParameter $Member
}
CSV Format:
UserId
12345678-90ab-cdef-1234-567890abcdef
23456789-0abc-def1-2345-67890abcdef1
PowerShell Script:
$GroupId = "87654321-fedc-ba98-7654-3210fedcba98"
$CsvPath = "C:\Path\To\Users.csv"
$Users = Import-Csv -Path $CsvPath
foreach ($User in $Users) {
$NewMember = @{
"@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/$($User.UserId)"
}
New-MgGroupMemberByRef -GroupId $GroupId -BodyParameter $NewMember
}
This script imports user IDs from a CSV file and adds them to the specified group.
| Key Point | Details |
| Cmdlet Name | New-MgGroupMemberByRef |
| Purpose | Adds a user/object to a Microsoft 365 or security group |
| Required Scope | Group.ReadWrite.All |
| Primary Parameters | GroupId, BodyParameter |
| Automation Benefit | Bulk membership changes via loops/CSV without Admin Center |
| Use Case | Onboarding, project access provisioning, mass group updates |
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