As Microsoft retires the AzureAD module, it's essential for administrators to migrate their group membership management scripts to the Microsoft Graph PowerShell SDK. One of the most commonly used cmdlets in group management was Add-AzureADGroupMember, which allowed admins to assign users to Microsoft 365 groups.
In this article, you’ll learn how to transition to the Graph-based alternative — New-MgGroupMemberByRef — including key syntax changes, usage examples, and the advantages of moving to Microsoft Graph.
The Add-AzureADGroupMember cmdlet allowed you to add users to a group using their object IDs, typically referencing the group by its ObjectId as well.
Example: Add a Single User to a Group
Add-AzureADGroupMember -ObjectId "87654321-fedc-ba98-7654-3210fedcba98" `-RefObjectId "12345678-90ab-cdef-1234-567890abcdef"
This added the user with the specified ID to the group. You could also use a CSV file for bulk additions.
The Graph equivalent is New-MgGroupMemberByRef. Instead of passing just the GUID of the user, you now pass the full Microsoft Graph API reference to the user as an @odata.id.
$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 is ideal for bulk group member assignment based on exported user data or HR system input.
🔄 Old (Add-AzureADGroupMember) | ➡️ New (New-MgGroupMemberByRef) |
Parameter: -ObjectId, -RefObjectId | Parameter: -GroupId, -BodyParameter |
Passed user ID directly | Requires full @odata.id Graph URI |
AzureAD module (deprecated) | Microsoft.Graph.Groups module |
No Graph API alignment | Fully Graph API-compliant |
Limited extensibility | Easily automatable for bulk/group-based workflows |
Migrating from Add-AzureADGroupMember to New-MgGroupMemberByRef may look like a more structured change, but it gives you better integration with Graph, enhanced automation capabilities, and aligns your scripts with Microsoft’s future-ready administration toolkit.
Whether you're adding a single user, multiple users, or importing from a CSV, the new Graph-based method is secure, scalable, and here to stay.
Visit M365Corner.com for ready-to-use free Microsoft Graph PowerShell tools and step-by-step migration guides built for Microsoft 365 administrators.
© Your Site Name. All Rights Reserved. Design by HTML Codex