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

!Daniel Bradley 1,071 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

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Graph
0 comments No comments

Answer accepted by question author

HarmeetSingh7172 4,831 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.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.