What is the different between New-MgGroupMember and New-MgGroupMemberByRef?

!Daniel Bradley 1,056 Reputation points MVP
2023-02-09T10:02:37.0933333+00:00

Hi All,

I am curious, what is the difference between using New-MgGroupMember and New-MgGroupMemberByRef?

I know how to use them both and I know for New-MgGroupMemberByRef you need to use an Odata bind defined within a hashtable. But why are there different commands to achieve the same result? Am I missing the reasoning behind there being two very similar commands like this? the same goes with all the other duplicate commands that are appended with 'ByRef'..

Thank you
Dan

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,472 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,014 questions
0 comments No comments
{count} votes

Accepted answer
  1. HarmeetSingh7172 4,811 Reputation points
    2023-02-09T23:04:25.56+00:00

    Hello !Daniel Bradley

    Thanks for reaching out!

    As per my understanding, both cmdlets let you create a member in a group. New-MgGroupMember cmdlet adds a member to an Office 365/security group through the members navigation property whereas New-MgGroupMemberByRef creates new navigation property ref to members for group.

    Sample query using New-MgGroupMember:

    New-MgGroupMember -GroupId '987648e7-b23a-4328-bd46-f1bd431c2354' -DirectoryObjectId '6aqc50d3-fcbd-4727-a889-8ab232dfea01'
    

    Here we are straightforwarding passing the value. This adds a member specified by the DirectoryObjectId to the specified group.

    Sample query using New-MgGroupMemberByRef:

    Import-Module Microsoft.Graph.Groups
    $params = @{
    	"@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/{id}"
    }
    New-MgGroupMemberByRef -GroupId $groupId -BodyParameter $params
    
    

    We make use of HashTable while using above cmdlet.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.

    0 comments No comments

0 additional answers

Sort by: Most helpful