Migrating from Add-AzureADGroupMember to New-MgGroupMemberByRef

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.


What You Did Previously with Add-AzureADGroupMember

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.


What You Should Do Now with New-MgGroupMemberByRef

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.


Adding a Single Member to a Group

$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
                                        

Adding Multiple Members to a Group

$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
}
                                        

Importing Members from a CSV File

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.


What’s Different with New-MgGroupMemberByRef?


🔄 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

Conclusion

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.


Permission Required

Example:


                                


                                


                                

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