The New-MgGroupOwnerByRef cmdlet in Microsoft Graph PowerShell is used to add one or more owners to an existing Microsoft 365 group. Owners have elevated permissions, such as managing group membership, settings, and overall group administration.
Adding owners to groups is essential for delegating administration, improving group governance, and ensuring redundancy if the primary owner is unavailable. With this cmdlet, administrators can automate the process of assigning ownership to multiple groups, streamlining operations in large tenants.
Before running this cmdlet, install and connect to Microsoft Graph PowerShell with the required permissions:
Connect-MgGraph -Scopes "Group.ReadWrite.All"
The basic syntax is:
New-MgGroupOwnerByRef -GroupId -BodyParameter <Hashtable>
The GroupId is the unique identifier of the group, while the BodyParameter specifies the owner’s reference using their unique user ID.
$Owner = @{
"@odata.id" = "https://graph.microsoft.com/v1.0/users/{UserId}"
}
New-MgGroupOwnerByRef -GroupId "5c67f5b3-b1c4-4c16-842d-11b453b6f270" -BodyParameter $Owner
This command adds a single owner to the specified group. Replace {UserId} with the actual ID of the user.
$Owners = @(
@{
"@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/2017e571-90fd-4671-96bb-360c678f4d23"
}
@{
"@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/55bafc67-7ba0-4964-840a-53d480542ab8"
}
)
foreach ($Owner in $Owners) {
New-MgGroupOwnerByRef -GroupId "3a408d7b-d2d1-4ec6-812f-b9ad64187a13" -BodyParameter $Owner
}
This script adds multiple owners to a group by iterating through the owners list.
$OwnersFromCSV = Import-Csv -Path "C:\Path\To\Owners.csv"
foreach ($Owner in $OwnersFromCSV) {
$OwnerHash = @{
"@odata.id" = "https://graph.microsoft.com/v1.0/users/$($Owner.UserId)"
}
New-MgGroupOwnerByRef -GroupId "5c67f5b3-b1c4-4c16-842d-11b453b6f270" -BodyParameter $OwnerHash
}
This script imports owner details from a CSV and assigns each user as a group owner.
CSV File Format
UserId
12345678-90ab-cdef-1234-567890abcdef
23456789-0abc-def1-2345-67890abcdef1
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