Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitIn Microsoft 365, group owners hold elevated privileges — including the ability to manage membership, settings, and integrations. When an owner is removed from a group, it’s important to know who performed the action, when it happened, and who was affected.
This article introduces a Graph PowerShell script that retrieves and reports all 'Remove owner from group' audit events under the GroupManagement category, along with:
# Connect to Microsoft Graph with required scopes
Connect-MgGraph -Scopes "AuditLog.Read.All", "Group.Read.All"
# Define the Graph API URI for the audit log query
$uri = "https://graph.microsoft.com/v1.0/auditLogs/directoryAudits" +
"?`$filter=activityDisplayName eq 'Remove owner from group' and category eq 'GroupManagement'" +
"&`$orderby=activityDateTime desc"
# Call Graph API using Invoke-MgGraphRequest
$response = Invoke-MgGraphRequest -Method GET -Uri $uri
# Prepare result collection
$results = @()
foreach ($entry in $response.value) {
try {
$removedTime = $entry.activityDateTime
$operation = $entry.activityDisplayName
$actorUPN = $entry.initiatedBy.user.userPrincipalName
$groupId = ""
$groupName = ""
$removedOwnerUPN = ""
# Extract group ID and removed owner's UPN
foreach ($target in $entry.targetResources) {
if ($target.type -eq "Group" -and $target.id) {
$groupId = $target.id
}
if ($target.type -eq "User" -and $target.userPrincipalName) {
$removedOwnerUPN = $target.userPrincipalName
}
}
# Resolve group name using groupId
if ($groupId) {
try {
$group = Get-MgGroup -GroupId $groupId -Property DisplayName -ErrorAction Stop
$groupName = $group.DisplayName
} catch {
$groupName = "[Unknown Group]"
}
}
# Add result to output
$results += [PSCustomObject]@{
'Removed Time' = $removedTime
'Group Name' = $groupName
'Operation' = $operation
'Removed Owner' = $removedOwnerUPN
'Removed By' = $actorUPN
}
} catch {
Write-Warning "Error processing entry: $($_)"
}
}
# Output final report
if ($results.Count -eq 0) {
Write-Host "No 'Remove owner from group' events found in audit logs." -ForegroundColor Yellow
} else {
$results | Sort-Object 'Removed Time' -Descending | Format-Table -AutoSize
}
This script uses the following Microsoft Graph delegated permissions:
Using Connect-MgGraph, it grants access to audit log and group resources.
Filters entries by:
activityDisplayName eq 'Remove owner from group' and category eq 'GroupManagement'
From each log entry, it captures:
Since audit logs return only group IDs, the script calls Get-MgGroup to retrieve the actual group name (DisplayName).
Outputs a clean table showing all key details related to owner removal events.
You can extend the script with the following features:
For reporting or archival:
$results | Export-Csv -Path "RemovedGroupOwners.csv" -NoTypeInformation
Use a $filter parameter to restrict results to the last 30 or 90 days:
...&`$filter=activityDisplayName eq 'Remove owner from group' and activityDateTime ge 2024-06-01T00:00:00Z
Fetch additional metadata using:
Get-MgGroup -GroupId $groupId -Property GroupTypes, Description
Integrate into a scheduled job or alerting workflow for real-time detection of high-risk owner removals.
Error | Cause | Solution |
Access Denied | Missing Graph permissions | Use AuditLog.Read.All, Group.Read.All when connecting |
Get-MgGroup : Resource not found | Group was deleted or soft-deleted | Use try/catch and label as [Unknown Group] |
targetResources.userPrincipalName is null | Target does not include UPN | Skip or flag such entries gracefully |
No events found | No owner removal activity in the time window | Confirm activity via Entra portal or adjust filters |
Here are some practical use cases for this script:
Detect unexpected changes in group ownership, especially for critical teams or admin groups.
Maintain audit trails of permission changes for external audits or regulatory frameworks.
See when and by whom a group owner was removed in case of access disruptions.
Assist with periodic access reviews and internal audits to ensure proper ownership.
Tracking when a group owner is removed is a crucial part of group governance in Microsoft 365. This Graph PowerShell script leverages audit logs and group metadata to give you a clear, actionable audit trail of ownership removals across your tenant.
By running this regularly, you can tighten your security posture, support compliance, and maintain full visibility over group-level administrative activity.
© m365corner.com. All Rights Reserved. Design by HTML Codex