Adding users to Microsoft 365 groups is a common task for IT administrators. While the Microsoft 365 admin portal allows for manual group management, PowerShell provides a faster, repeatable, and scalable way to handle group membership—especially when dealing with multiple users.
In this article, we’ll walk you through how to use the New-MgGroupMemberByRef cmdlet to add members to Microsoft 365 groups efficiently using Microsoft Graph PowerShell.
New-MgGroupMemberByRef is a Microsoft Graph PowerShell cmdlet that allows you to add a member to a Microsoft 365 Group by referencing the user's directory object ID (GUID).
Instead of using email addresses or display names, this cmdlet uses a specific object reference URL, making it accurate and script-friendly for automation tasks.
Here are a few reasons why admins choose this method:
New-MgGroupMemberByRef -GroupId <String> -BodyParameter <Hashtable>
Parameters:
$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
}
$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
}
UserId
12345678-90ab-cdef-1234-567890abcdef
23456789-0abc-def1-2345-67890abcdef1
No, this cmdlet requires the directory object ID of the user. If you only have the email, you can retrieve the ID using:
(Get-MgUser -UserPrincipalName "user@domain.com").Id
Yes! If the Microsoft 365 Group is backed by a Team, adding the user to the group will make them a member of the Team as well.
You'll need Group.ReadWrite.All permission when connecting with Connect-MgGraph. Admin consent is required.
Here are some practical scenarios for using New-MgGroupMemberByRef:
The New-MgGroupMemberByRef cmdlet is a powerful, precise, and scalable tool for adding members to Microsoft 365 Groups using Graph PowerShell. Whether you're working with a single user, multiple members, or importing from CSV, this cmdlet fits perfectly into your IT automation toolkit.
Take control of your group membership tasks and streamline user provisioning—all from your PowerShell console.
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