Query Details
//Original Source: https://azurewithtom.com/posts/MSRC-Case-When-Temporary-Global-Admin-Rights-Don-t-Expire-in-Microsoft-Entra-PIM/
AuditLogs
| where TimeGenerated >= ago(90d)
| where OperationName == "Remove eligible member from role in PIM completed (timebound)"
| where Result == "failure"
| where ResultReason contains "CannotDeleteLastAdminAssignment"
| extend
TargetUser = tostring(TargetResources[2].userPrincipalName),
RoleName = tostring(TargetResources[0].displayName)
//| where RoleName == "Global Administrator" //if you want scope to only GA as per the original article
| project
TimeGenerated,
OperationName,
TargetUser,
RoleName,
ResultReason,
CorrelationId
| sort by TimeGenerated desc
//Always maintain a breakglass. see my article on breakglass guidance here https://www.linkedin.com/pulse/main-reason-you-shouldnt-exclude-break-glass-group-access-kerai-4dtve/
This query is designed to analyze audit logs in Microsoft Entra (formerly Azure Active Directory) to identify instances where attempts to remove a user from a role in Privileged Identity Management (PIM) failed. Specifically, it looks for failures due to the reason "CannotDeleteLastAdminAssignment," which indicates that the operation could not be completed because it would result in no remaining administrators for that role.
Here's a simplified breakdown of what the query does:
The query can be further refined to focus only on the "Global Administrator" role by uncommenting the specified line. Additionally, the note at the end emphasizes the importance of maintaining a "breakglass" account, which is an emergency account with elevated privileges that can be used if normal administrative access is lost.

Jay Kerai
Released: October 19, 2025
Tables
Keywords
Operators