The Remove-MgGroupOwnerByRef cmdlet in Microsoft Graph PowerShell removes one or more owners from a specified Microsoft 365 group. Group owners are users with administrative privileges who can manage group settings, membership, and associated resources. This cmdlet is especially helpful for administrators who need to automate owner removal tasks across large environments.
This cmdlet allows Microsoft 365 administrators to efficiently manage group ownership without using the admin center manually. It is highly valuable when performing:
Before running this cmdlet, connect to Microsoft Graph with the proper permissions.
Connect-MgGraph -Scopes "Group.ReadWrite.All""
This permission allows you to modify group memberships, including adding or removing group owners.
You must specify both the GroupId and DirectoryObjectId (owner’s unique ID). The basic syntax is:
Remove-MgGroupOwnerByRef -GroupId <String> -DirectoryObjectId <String>
Example 1: Single Removal of Group Owner
This example demonstrates removing a single owner from a specified group using the group ID and owner ID.
Remove-MgGroupOwnerByRef -GroupId "12345678-9abc-def0-1234-56789abcdef0" -DirectoryObjectId "87654321-fedc-ba98-7654-3210fedcba98"
Example 2: Removing Multiple Owners from a Group
To remove multiple owners, you can iterate through a list of owner IDs.
$GroupId = "12345678-9abc-def0-1234-56789abcdef0"
$Owners = @("87654321-fedc-ba98-7654-3210fedcba98", "01234567-89ab-cdef-0123-456789abcdef")
foreach ($Owner in $Owners) {
Remove-MgGroupOwnerByRef -GroupId $GroupId -DirectoryObjectId $Owner
}
Example 3: Bulk Removal by Reading Data from a CSV File
For large-scale environments, removing owners in bulk is best handled via CSV import.
Sample CSV File:
DirectoryObjectId
87654321-fedc-ba98-7654-3210fedcba98
01234567-89ab-cdef-0123-456789abcdef
$GroupId = "12345678-9abc-def0-1234-56789abcdef0"
$CsvData = Import-Csv -Path "C:\path\to\owners.csv"
foreach ($Owner in $CsvData) {
Remove-MgGroupOwnerByRef -GroupId $GroupId -DirectoryObjectId $Owner.DirectoryObjectId
}
This script automates the removal of multiple owners by reading their IDs from a CSV file.
| Key Point | Details |
|---|---|
| Cmdlet Name | Remove-MgGroupOwnerByRef |
| Purpose | Removes specified owners from a Microsoft 365 group |
| Required Scope | Group.ReadWrite.All |
| Primary Parameter | GroupId, DirectoryObjectId |
| Automation Benefit | Enables administrators to automate the cleanup and reassignment of group owners |
| Use Case | Ideal for removing outdated, inactive, or unauthorized group owners efficiently |
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