Set Up Microsoft Entra PIM: A Step-by-Step Guide
Summary
Microsoft Entra Privileged Identity Management (PIM), still called Azure PIM, replaces standing administrator rights with eligible role assignments that people activate only when they need them, for a limited time, with MFA, a justification and approval. To set it up, license the right users, audit current assignments, tighten role settings, convert permanent assignments to eligible ones, and monitor every activation.
Quick steps
- Confirm Microsoft Entra ID P2 or Microsoft Entra ID Governance licenses for every eligible user, approver and reviewer.
- Create two or more cloud-only emergency access accounts and keep their Global Administrator assignment permanent active.
- Run the read-only audit script to export every active and eligible role assignment and flag the permanent active ones.
- Set the role settings of Tier 0 roles: a short activation, MFA or an authentication context, a justification, a ticket and approval.
- Convert permanent active assignments to time-bound eligible ones, in the portal or with Microsoft Graph PowerShell.
- Bring role-assignable groups and Azure resource roles under PIM.
- Turn on access reviews and PIM alerts, and alert on any assignment made outside PIM.
Applies to: Microsoft Entra ID with Microsoft Entra ID P2 or Microsoft Entra ID Governance licenses, Microsoft Entra roles, PIM for Groups and Azure resource roles (as of November 2026). The scripts use the Microsoft Graph PowerShell v1.0 cmdlets and run in Windows PowerShell 5.1.
What is Microsoft Entra Privileged Identity Management and why does it matter?
Microsoft Entra Privileged Identity Management is a service in Microsoft Entra ID that manages, controls and monitors access to privileged roles in Microsoft Entra ID, Azure and other Microsoft online services such as Microsoft 365 and Intune. It gives administrators just-in-time access: a role assignment that sits unused until the person activates it, then expires. Our glossary entry on privileged identity management covers the concept; this guide covers the setup.
Microsoft's PIM overview lists time-bound assignments, approval, MFA and a justification on activation, notifications, access reviews and audit history. PIM also prevents removal of the last active Global Administrator and Privileged Role Administrator assignments.
A standing assignment is always ready for whoever controls the account. An attacker who signs in as a permanent Global Administrator controls the tenant at once, and adding a role to an account the attacker controls is MITRE ATT&CK T1098.003, Account Manipulation: Additional Cloud Roles. With PIM, an eligible account must pass the activation checks first, and every assignment and activation leaves an audit record. PIM is also a target: anyone who can change its role settings can remove approval or MFA.
Eligible vs active assignments
An eligible assignment requires the user to activate the role before using it, while an active assignment works without any action. Microsoft notes that the access itself is the same; the difference is that the eligible user holds it only after activation. Each type can be permanent or time-bound, which gives four combinations:
| Assignment | What the member can do | Typical use |
|---|---|---|
| Permanent eligible | Activate the role at any time | Not recommended for Tier 0 roles; prefer an end date |
| Time-bound eligible | Activate the role between the start and end dates | Administrators and contractors |
| Time-bound active | Use the role between the start and end dates, without activating it | Short projects, and service principals, which can't be eligible |
| Permanent active | Use the role at all times | Emergency access accounts only |
The PIM deployment plan says to keep zero permanently active assignments for roles other than your emergency access accounts. It also notes that service principals can't be assigned as eligible to Microsoft Entra roles, Azure roles or PIM for Groups, though they can receive a time-limited active assignment.
What licenses does Microsoft Entra PIM need?
PIM needs Microsoft Entra ID P2 or Microsoft Entra ID Governance licenses. Microsoft Entra ID P2 is sold on its own and is part of Microsoft 365 E5 and E7; the Microsoft Entra ID Governance products need a P1 or P2 prerequisite in the tenant. Microsoft's licensing fundamentals list who must be covered (as of November 2026):
| Who | License |
|---|---|
| Users with eligible or time-bound assignments to Microsoft Entra roles or Azure roles managed in PIM | Microsoft Entra ID P2 or Microsoft Entra ID Governance |
| Users with eligible or time-bound membership or ownership in PIM for Groups | Microsoft Entra ID P2 or Microsoft Entra ID Governance |
| Users who approve or reject activation requests | Microsoft Entra ID P2 or Microsoft Entra ID Governance |
| Users assigned to an access review, and the reviewers | Microsoft Entra ID P2 or Microsoft Entra ID Governance; access reviews of service principals also need Microsoft Entra Workload ID Premium |
Microsoft's licensing FAQ says Microsoft Entra ID Governance licenses don't have to be assigned to each user, but you need enough to cover every member user in scope. Watch the expiry dates, because a lapsed license changes your assignments (see Roll back).
Before you start
Prepare the right administrators, emergency access, a pilot and the tooling. Test the whole sequence in a lab tenant first, because a wrong approval setting can lock every administrator out.
Who can configure PIM?
- Microsoft Entra roles: only Privileged Role Administrator or Global Administrator can manage assignments for other administrators and change role settings. Security Administrator, Global Reader and Security Reader can view assignments.
- Azure resource roles: a subscription administrator, a resource Owner or a User Access Administrator.
- Approvers don't need any role, but they need a license.
Emergency access accounts come first
Microsoft recommends two or more cloud-only emergency access accounts (break glass accounts) that use the *.onmicrosoft.com domain and aren't federated or synchronized. In PIM, their Global Administrator assignment should be permanent active, not eligible. Protect them with a phishing-resistant method that your daily admins don't use, such as a passkey (FIDO2), and exclude them from Conditional Access policies that block or restrict sign-in. The break glass accounts guide walks through the setup and the sign-in alerts.
Warning: Microsoft's role settings article warns that you'll be locked out of your tenant when all Privileged Role Administrators and Global Administrators are eligible with none active, approval is required, and no approvers are configured. Active emergency access accounts and named approvers prevent this.
Plan the pilot and the change window
- Start with a small pilot group, as Microsoft's deployment plan advises. For Microsoft Entra roles, organizations often roll out Global Administrators first; for Azure resources, one subscription at a time.
- Tell administrators how activation works, and that a pending request expires if nobody approves it within 24 hours.
- A new assignment can't last less than five minutes and can't be removed within five minutes of being created.
- Install the Microsoft Graph PowerShell SDK on an admin workstation. The scripts below need the
Microsoft.Graph.Authentication,Microsoft.Graph.Identity.Governance,Microsoft.Graph.Identity.SignInsandMicrosoft.Graph.DirectoryObjectsmodules.
Step 1: Audit current privileged role assignments
Start with an inventory of who holds which Microsoft Entra role, and how. The script below reads every active and eligible role assignment, including direct assignments made outside PIM, and flags each permanent active one. It is read-only.
Run it on an admin workstation as Global Reader or Privileged Role Administrator. The list APIs accept RoleManagement.Read.Directory, and resolving principal names needs Directory.Read.All:
Connect-MgGraph -Scopes 'RoleManagement.Read.Directory', 'Directory.Read.All'
#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.Authentication, Microsoft.Graph.Identity.Governance, Microsoft.Graph.DirectoryObjects
<#
.SYNOPSIS
Read-only export of Microsoft Entra role assignments, active and eligible, with permanent active ones flagged.
.DESCRIPTION
Reads the role definitions, the active role assignment instances and the eligible role
assignment instances of the tenant through Microsoft Graph. The active instances include
assignments made through PIM and assignments made directly, outside PIM.
Each output row is one assignment: the role, whether Microsoft Entra ID marks the role as
privileged, the principal and its type, the member type (Direct, Group or Inherited), the
state (PermanentActive, TimeBoundActive, Activated, PermanentEligible or TimeBoundEligible)
and the end time. A permanent active row is flagged for review unless its principal is in
ExpectedPermanentPrincipalId, the list of your emergency access accounts.
Writes one CSV file and returns a summary object. It reads no secret and changes nothing.
.PARAMETER OutputPath
Path of the CSV report, for example 'C:\Reports\PIM\pim-role-assignments.csv'.
.PARAMETER ExpectedPermanentPrincipalId
Object IDs of the principals that may keep a permanent active assignment, normally the
emergency access accounts, for example '00000000-0000-0000-0000-000000000000'.
.PARAMETER PrivilegedOnly
Report only roles whose isPrivileged property is true.
.EXAMPLE
.\Get-EntraPimRoleAssignmentAudit.ps1 -OutputPath 'C:\Reports\PIM\pim-role-assignments.csv'
.EXAMPLE
.\Get-EntraPimRoleAssignmentAudit.ps1 -OutputPath 'C:\Reports\PIM\pim-role-assignments.csv' -PrivilegedOnly -ExpectedPermanentPrincipalId '00000000-0000-0000-0000-000000000000'
.NOTES
Read-only. Makes no change in Microsoft Entra ID. Writes only the CSV report.
Run it in a session opened with:
Connect-MgGraph -Scopes 'RoleManagement.Read.Directory','Directory.Read.All'
as a user who holds a role that can read role definitions and role assignments, for
example Global Reader or Privileged Role Administrator.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$OutputPath,
[string[]]$ExpectedPermanentPrincipalId = @(),
[switch]$PrivilegedOnly
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$context = Get-MgContext
if ($null -eq $context) {
throw 'No Microsoft Graph session. Run Connect-MgGraph first.'
}
$reportFolder = Split-Path -Path $OutputPath -Parent
if ($reportFolder -and -not (Test-Path -Path $reportFolder -PathType Container)) {
throw "Report folder not found: $reportFolder"
}
function Get-ExtraValue {
param($InputObject, [string]$Name)
if ($null -eq $InputObject) { return $null }
# A property the SDK model declares (for example IsPrivileged) is read from the object itself;
# any other property is read from AdditionalProperties.
$declared = $InputObject.PSObject.Properties[$Name]
if ($null -ne $declared -and $null -ne $declared.Value) { return $declared.Value }
$extra = $InputObject.AdditionalProperties
if ($null -ne $extra -and $extra.ContainsKey($Name)) { return $extra[$Name] }
return $null
}
# 1. Role definitions, with the isPrivileged flag
$roles = @{}
foreach ($definition in @(Get-MgRoleManagementDirectoryRoleDefinition -All -Property 'id', 'displayName', 'isBuiltIn', 'isPrivileged')) {
$roles[$definition.Id] = $definition
}
# 2. Active and eligible assignment instances
$active = @(Get-MgRoleManagementDirectoryRoleAssignmentScheduleInstance -All)
$eligible = @(Get-MgRoleManagementDirectoryRoleEligibilityScheduleInstance -All)
# 3. Resolve the principals, up to 1,000 IDs per request
$principalIds = @(@($active) + @($eligible) | ForEach-Object { $_.PrincipalId } | Sort-Object -Unique)
$principals = @{}
for ($i = 0; $i -lt $principalIds.Count; $i += 1000) {
$last = [Math]::Min($i + 999, $principalIds.Count - 1)
foreach ($object in @(Get-MgDirectoryObjectById -Ids $principalIds[$i..$last])) {
$principals[$object.Id] = $object
}
}
# 4. One row per assignment
$entries = @(
foreach ($instance in $active) { [pscustomobject]@{ Kind = 'Active'; Instance = $instance } }
foreach ($instance in $eligible) { [pscustomobject]@{ Kind = 'Eligible'; Instance = $instance } }
)
$rows = @(foreach ($entry in $entries) {
$instance = $entry.Instance
$role = $roles[$instance.RoleDefinitionId]
$isPrivileged = Get-ExtraValue -InputObject $role -Name 'isPrivileged'
if ($PrivilegedOnly -and $isPrivileged -ne $true) { continue }
if ($entry.Kind -eq 'Active') {
if ($instance.AssignmentType -eq 'Activated') { $state = 'Activated' }
elseif ($null -eq $instance.EndDateTime) { $state = 'PermanentActive' }
else { $state = 'TimeBoundActive' }
}
else {
if ($null -eq $instance.EndDateTime) { $state = 'PermanentEligible' }
else { $state = 'TimeBoundEligible' }
}
$principal = $principals[$instance.PrincipalId]
$principalType = [string](Get-ExtraValue -InputObject $principal -Name '@odata.type')
$principalType = $principalType -replace '^#microsoft\.graph\.', ''
$finding = ''
if ($state -eq 'PermanentActive') {
if ($ExpectedPermanentPrincipalId -contains $instance.PrincipalId) { $finding = 'Expected: emergency access' }
else { $finding = 'Review: permanent active' }
}
[pscustomobject]@{
RoleName = if ($role) { $role.DisplayName } else { $instance.RoleDefinitionId }
RoleIsPrivileged = $isPrivileged
RoleIsBuiltIn = if ($role) { $role.IsBuiltIn } else { $null }
PrincipalName = Get-ExtraValue -InputObject $principal -Name 'displayName'
PrincipalUpn = Get-ExtraValue -InputObject $principal -Name 'userPrincipalName'
PrincipalType = $principalType
PrincipalId = $instance.PrincipalId
DirectoryScopeId = $instance.DirectoryScopeId
MemberType = $instance.MemberType
State = $state
StartUtc = $instance.StartDateTime
EndUtc = $instance.EndDateTime
Finding = $finding
}
})
# 5. Report and summary
$rows | Export-Csv -Path $OutputPath -NoTypeInformation -Encoding UTF8
[pscustomobject]@{
TenantId = $context.TenantId
PrivilegedOnly = [bool]$PrivilegedOnly
RolesWithAssignments = @($rows | Select-Object -ExpandProperty RoleName -Unique).Count
Assignments = $rows.Count
PermanentActive = @($rows | Where-Object { $_.State -eq 'PermanentActive' }).Count
PermanentActiveToReview = @($rows | Where-Object { $_.Finding -eq 'Review: permanent active' }).Count
TimeBoundActive = @($rows | Where-Object { $_.State -eq 'TimeBoundActive' }).Count
ActivatedNow = @($rows | Where-Object { $_.State -eq 'Activated' }).Count
PermanentEligible = @($rows | Where-Object { $_.State -eq 'PermanentEligible' }).Count
TimeBoundEligible = @($rows | Where-Object { $_.State -eq 'TimeBoundEligible' }).Count
ServicePrincipalRows = @($rows | Where-Object { $_.PrincipalType -eq 'servicePrincipal' }).Count
GroupRows = @($rows | Where-Object { $_.PrincipalType -eq 'group' }).Count
Report = $OutputPath
}
Run it for the roles Microsoft Entra ID marks as privileged, and pass the object IDs of your emergency access accounts:
.\Get-EntraPimRoleAssignmentAudit.ps1 -OutputPath 'C:\Reports\PIM\pim-role-assignments.csv' -PrivilegedOnly -ExpectedPermanentPrincipalId '00000000-0000-0000-0000-000000000000'
Example output (the values are illustrative):
TenantId : 00000000-0000-0000-0000-000000000000
PrivilegedOnly : True
RolesWithAssignments : 11
Assignments : 47
PermanentActive : 14
PermanentActiveToReview : 12
TimeBoundActive : 1
ActivatedNow : 2
PermanentEligible : 18
TimeBoundEligible : 12
ServicePrincipalRows : 3
GroupRows : 2
Report : C:\Reports\PIM\pim-role-assignments.csv
How to read the results:
- Review: permanent active: a standing assignment that isn't one of your emergency access accounts. These are the first candidates for Step 3. Permanent assignments made outside PIM land here as well.
- Activated: an eligible member activated the role. The same person also has a
PermanentEligibleorTimeBoundEligiblerow, so don't count them twice. - PermanentEligible: eligibility with no end date. For Tier 0 roles, give it an end date and an access review.
- servicePrincipal rows: a workload identity with a directory role. It can't be made eligible, so give it a time-bound active assignment or remove the role. Treat these accounts as possible shadow admins.
- group rows: a role-assignable group holds the role, and every member of the group holds it too. Review the members, or manage the group with PIM for Groups (Step 5).
Step 2: Configure role settings for Tier 0 roles
Role settings decide what activation requires, how long it lasts and who is told. PIM keeps one set per role, every assignment of the role follows it, and Microsoft Graph calls them rules. Open them at ID Governance > Privileged Identity Management > Microsoft Entra roles > Roles, select the role, then Role settings > Edit, and save with Update.
Read your tenant's current values with the export script below before you change anything. The table lists each setting with its Graph rule ID and a starting point for the Tier 0 roles: Global Administrator, Privileged Role Administrator and Privileged Authentication Administrator.
| Setting | Where (tab / Graph rule ID) | Starting point for Tier 0 roles | Effect |
|---|---|---|---|
| Activation maximum duration | Activation / Expiration_EndUser_Assignment |
1 to 2 hours | Allowed range is 1 to 24 hours; Microsoft's example uses one hour for Global Administrator |
| On activation, require Azure MFA | Activation / Enablement_EndUser_Assignment (MultiFactorAuthentication) |
On, or use an authentication context | Users who already completed MFA in the session may not be prompted again |
| On activation, require Microsoft Entra Conditional Access authentication context | Activation / AuthenticationContext_EndUser_Assignment |
An authentication context that requires a phishing-resistant authentication strength | Forces the Conditional Access policy that targets the context at activation time |
| Require justification on activation | Activation / Enablement_EndUser_Assignment (Justification) |
On | The reason appears in the audit history |
| Require ticket information on activation | Activation / Enablement_EndUser_Assignment (Ticketing) |
On | Information only; PIM doesn't check the number against a ticketing system |
| Require approval to activate | Activation / Approval_EndUser_Assignment |
On, with two or more named approvers | Without named approvers, active Privileged Role Administrators and Global Administrators approve |
| Allow permanent eligible assignment / Expire eligible assignments after | Assignment / Expiration_Admin_Eligibility |
Expire, and renew through access reviews | Sets the longest eligibility an administrator can grant |
| Allow permanent active assignment / Expire active assignments after | Assignment / Expiration_Admin_Assignment |
Expire, except on Global Administrator if your emergency access accounts must stay permanent active | Blocks new standing access for the role |
| Require MFA and justification on active assignment | Assignment / Enablement_Admin_Assignment |
On | Applies to the administrator who creates an active assignment |
| Notifications | Notification / the Notification_* rules |
Add a monitored mailbox to the role activation alert | One event sends email to at most 1,000 recipients |
Settings are per role, so a Global Administrator rule that requires active assignments to expire also covers the active assignments you create for your emergency access accounts. Microsoft's emergency access guidance keeps those accounts permanent active, so we recommend leaving that one option allowed on Global Administrator and watching the role with the detection queries instead.
Use an authentication context instead of plain MFA
MFA on activation can pass silently when the user already authenticated strongly in the session. Microsoft's answer is the authentication context option: PIM then enforces a Conditional Access policy, for example one that requires a phishing-resistant authentication strength or a compliant device.
- Create and enable the Conditional Access policy for the authentication context before you select it in PIM. Scope it to all users or to the eligible users, never to the directory role, because the user doesn't hold the role yet during activation.
- Set its sign-in frequency to Every time under Session controls to force reauthentication on each activation. Microsoft applies a 10-minute window in which a second activation doesn't prompt again.
- Add a second policy that targets the directory roles, so the activated role can't be used from another device that ignores the first policy.
Whoever can edit those policies can weaken activation, so treat Conditional Access Administrator and Security Administrator as privileged.
Export the current settings (read-only)
This script reads the PIM policy and rules of each role and writes a CSV report and a JSON baseline. It changes nothing. Run it as Global Reader or Privileged Role Administrator after Connect-MgGraph -Scopes 'RoleManagementPolicy.Read.Directory','RoleManagement.Read.Directory'.
#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.Authentication, Microsoft.Graph.Identity.Governance, Microsoft.Graph.Identity.SignIns
<#
.SYNOPSIS
Read-only export of the PIM role settings (rules) of Microsoft Entra roles.
.DESCRIPTION
For each role, reads the role management policy that PIM assigns to it, with its rules,
and reports the activation maximum duration, what activation requires (MFA, justification,
ticket), the authentication context, approval, and whether permanent eligible and
permanent active assignments are allowed. Weak settings are listed in the Findings column.
By default it reads every role whose isPrivileged property is true. Use RoleName to name
the roles instead. Writes a CSV report and a JSON baseline of the raw rules that you can
compare against later. It changes nothing.
.PARAMETER OutputPath
Path of the CSV report, for example 'C:\Reports\PIM\pim-role-settings.csv'.
.PARAMETER BaselinePath
Path of the JSON baseline, for example 'C:\Reports\PIM\pim-role-settings-baseline.json'.
.PARAMETER RoleName
Optional display names of the roles to read, for example 'Global Administrator'.
.EXAMPLE
.\Get-EntraPimRoleSettings.ps1 -OutputPath 'C:\Reports\PIM\pim-role-settings.csv' -BaselinePath 'C:\Reports\PIM\pim-role-settings-baseline.json'
.EXAMPLE
.\Get-EntraPimRoleSettings.ps1 -OutputPath 'C:\Reports\PIM\tier0-settings.csv' -BaselinePath 'C:\Reports\PIM\tier0-baseline.json' -RoleName 'Global Administrator', 'Privileged Role Administrator'
.NOTES
Read-only. Makes no change in Microsoft Entra ID. Writes only the two report files.
Run it in a session opened with:
Connect-MgGraph -Scopes 'RoleManagementPolicy.Read.Directory','RoleManagement.Read.Directory'
as a user who holds a role that can read PIM policies, for example Global Reader or
Privileged Role Administrator.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$OutputPath,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$BaselinePath,
[string[]]$RoleName = @()
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
if ($null -eq (Get-MgContext)) {
throw 'No Microsoft Graph session. Run Connect-MgGraph first.'
}
function Get-RuleValue {
param([hashtable]$Rules, [string]$RuleId, [string]$Name)
if (-not $Rules.ContainsKey($RuleId)) { return $null }
$extra = $Rules[$RuleId].AdditionalProperties
if ($null -ne $extra -and $extra.ContainsKey($Name)) { return $extra[$Name] }
return $null
}
function Get-DictionaryValue {
param($Dictionary, [string]$Name)
if ($Dictionary -is [System.Collections.IDictionary] -and @($Dictionary.Keys) -contains $Name) { return $Dictionary[$Name] }
return $null
}
function Test-PrivilegedRole {
param($Definition)
# isPrivileged is a declared property in current SDK models and an additional property in older ones
$declared = $Definition.PSObject.Properties['IsPrivileged']
if ($null -ne $declared -and $null -ne $declared.Value) { return ($declared.Value -eq $true) }
$extra = $Definition.AdditionalProperties
return ($null -ne $extra -and $extra.ContainsKey('isPrivileged') -and $extra['isPrivileged'] -eq $true)
}
# 1. Roles to read
$definitions = @(Get-MgRoleManagementDirectoryRoleDefinition -All -Property 'id', 'displayName', 'isPrivileged')
if ($RoleName.Count -gt 0) {
$targets = @($definitions | Where-Object { $RoleName -contains $_.DisplayName })
$missing = @($RoleName | Where-Object { @($definitions.DisplayName) -notcontains $_ })
if ($missing.Count -gt 0) { throw "Role not found: $($missing -join ', ')" }
}
else {
$targets = @($definitions | Where-Object { Test-PrivilegedRole -Definition $_ })
}
# 2. Policy and rules of each role
$rows = New-Object System.Collections.Generic.List[object]
$baseline = New-Object System.Collections.Generic.List[object]
foreach ($role in $targets) {
$filter = "scopeId eq '/' and scopeType eq 'DirectoryRole' and roleDefinitionId eq '$($role.Id)'"
$assignment = @(Get-MgPolicyRoleManagementPolicyAssignment -Filter $filter -ExpandProperty 'policy($expand=rules)')
if ($assignment.Count -eq 0) {
Write-Warning "No PIM policy found for $($role.DisplayName)."
continue
}
$rules = @{}
foreach ($rule in @($assignment[0].Policy.Rules)) { $rules[$rule.Id] = $rule }
$activationRules = @(Get-RuleValue -Rules $rules -RuleId 'Enablement_EndUser_Assignment' -Name 'enabledRules')
$authContextOn = (Get-RuleValue -Rules $rules -RuleId 'AuthenticationContext_EndUser_Assignment' -Name 'isEnabled') -eq $true
$authContext = if ($authContextOn) { Get-RuleValue -Rules $rules -RuleId 'AuthenticationContext_EndUser_Assignment' -Name 'claimValue' } else { '' }
$approval = Get-DictionaryValue -Dictionary (Get-RuleValue -Rules $rules -RuleId 'Approval_EndUser_Assignment' -Name 'setting') -Name 'isApprovalRequired'
$eligibleExpiry = Get-RuleValue -Rules $rules -RuleId 'Expiration_Admin_Eligibility' -Name 'isExpirationRequired'
$activeExpiry = Get-RuleValue -Rules $rules -RuleId 'Expiration_Admin_Assignment' -Name 'isExpirationRequired'
$findings = New-Object System.Collections.Generic.List[string]
if (-not $authContextOn -and $activationRules -notcontains 'MultiFactorAuthentication') { $findings.Add('No MFA or authentication context on activation') }
if ($activationRules -notcontains 'Justification') { $findings.Add('No justification on activation') }
if ($approval -ne $true) { $findings.Add('No approval') }
if ($activeExpiry -ne $true) { $findings.Add('Permanent active assignments allowed') }
if ($eligibleExpiry -ne $true) { $findings.Add('Permanent eligible assignments allowed') }
$rows.Add([pscustomobject]@{
RoleName = $role.DisplayName
PolicyId = $assignment[0].PolicyId
ActivationMaxDuration = Get-RuleValue -Rules $rules -RuleId 'Expiration_EndUser_Assignment' -Name 'maximumDuration'
ActivationRequires = ($activationRules -join ',')
AuthenticationContext = $authContext
ApprovalRequired = $approval
PermanentEligibleAllowed = ($eligibleExpiry -ne $true)
EligibleMaxDuration = Get-RuleValue -Rules $rules -RuleId 'Expiration_Admin_Eligibility' -Name 'maximumDuration'
PermanentActiveAllowed = ($activeExpiry -ne $true)
ActiveMaxDuration = Get-RuleValue -Rules $rules -RuleId 'Expiration_Admin_Assignment' -Name 'maximumDuration'
ActiveAssignmentRequires = (@(Get-RuleValue -Rules $rules -RuleId 'Enablement_Admin_Assignment' -Name 'enabledRules') -join ',')
Findings = ($findings -join '; ')
})
$baseline.Add([pscustomobject]@{
RoleName = $role.DisplayName
RoleId = $role.Id
PolicyId = $assignment[0].PolicyId
Rules = @(foreach ($rule in @($assignment[0].Policy.Rules)) {
[pscustomobject]@{
Id = $rule.Id
Caller = $rule.Target.Caller
Level = $rule.Target.Level
Properties = $rule.AdditionalProperties
}
})
})
}
# 3. Reports
$rows | Export-Csv -Path $OutputPath -NoTypeInformation -Encoding UTF8
$baseline | ConvertTo-Json -Depth 10 | Set-Content -Path $BaselinePath -Encoding UTF8
$rows | Select-Object RoleName, ActivationMaxDuration, ActivationRequires, ApprovalRequired, PermanentActiveAllowed, Findings
.\Get-EntraPimRoleSettings.ps1 -OutputPath 'C:\Reports\PIM\tier0-settings.csv' -BaselinePath 'C:\Reports\PIM\tier0-baseline.json' -RoleName 'Global Administrator', 'Privileged Role Administrator', 'Privileged Authentication Administrator'
Example output (the values are illustrative):
RoleName : Global Administrator
ActivationMaxDuration : PT4H
ActivationRequires : MultiFactorAuthentication,Justification
ApprovalRequired : False
PermanentActiveAllowed : True
Findings : No approval; Permanent active assignments allowed; Permanent eligible assignments allowed
RoleName : Privileged Role Administrator
ActivationMaxDuration : PT4H
ActivationRequires : Justification
ApprovalRequired : False
PermanentActiveAllowed : True
Findings : No MFA or authentication context on activation; No approval; Permanent active assignments allowed; Permanent eligible assignments allowed
Apply the settings with Microsoft Graph PowerShell
The next script changes configuration. It updates the activation duration, the activation requirements and, optionally, the assignment expiry and approval rules of each role you name. It supports -WhatIf and -Confirm, and it leaves MFA to the Conditional Access policy when a role already uses an authentication context. Microsoft's rule update reference names Privileged Role Administrator as the least privileged role for the write, so run it as a Privileged Role Administrator after Connect-MgGraph -Scopes 'RoleManagementPolicy.ReadWrite.Directory','RoleManagement.Read.Directory'.
#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.Authentication, Microsoft.Graph.Identity.Governance, Microsoft.Graph.Identity.SignIns
<#
.SYNOPSIS
Tightens the PIM activation and assignment settings of one or more Microsoft Entra roles.
.DESCRIPTION
For each role, the script updates these PIM rules through Microsoft Graph:
Expiration_EndUser_Assignment : activation maximum duration, in hours.
Enablement_EndUser_Assignment : justification, plus MFA unless the role already uses an
authentication context, plus a ticket number if asked.
Expiration_Admin_Assignment : active assignments must expire (optional).
Expiration_Admin_Eligibility : eligible assignments must expire (optional).
Approval_EndUser_Assignment : approval by the members of one group (optional).
Run it with -WhatIf first. Each rule update asks for confirmation unless you pass
-Confirm:$false.
.PARAMETER RoleName
Display names of the roles to change, for example 'Global Administrator'.
.PARAMETER ActivationMaxHours
Activation maximum duration in hours, from 1 to 24.
.PARAMETER RequireTicket
Also require ticket information on activation.
.PARAMETER ActiveAssignmentMaxDays
Optional. Require active assignments to expire after this many days (the script accepts 1 to 365).
.PARAMETER EligibleAssignmentMaxDays
Optional. Require eligible assignments to expire after this many days (the script accepts 1 to 365).
.PARAMETER ApproverGroupId
Optional. Object ID of the group whose members approve activations, for example
'00000000-0000-0000-0000-000000000000'.
.EXAMPLE
.\Set-EntraPimRoleSettings.ps1 -RoleName 'Global Administrator' -ActivationMaxHours 2 -RequireTicket -ActiveAssignmentMaxDays 15 -ApproverGroupId '00000000-0000-0000-0000-000000000000' -WhatIf
.EXAMPLE
.\Set-EntraPimRoleSettings.ps1 -RoleName 'Exchange Administrator', 'SharePoint Administrator' -ActivationMaxHours 4 -EligibleAssignmentMaxDays 180
.NOTES
Changes configuration. Updates PIM role settings (policy rules) in Microsoft Entra ID.
Export the current settings with Get-EntraPimRoleSettings.ps1 before you run it.
Run it in a session opened with:
Connect-MgGraph -Scopes 'RoleManagementPolicy.ReadWrite.Directory','RoleManagement.Read.Directory'
as a Privileged Role Administrator.
#>
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string[]]$RoleName,
[Parameter(Mandatory = $true)]
[ValidateRange(1, 24)]
[int]$ActivationMaxHours,
[switch]$RequireTicket,
[ValidateRange(1, 365)]
[int]$ActiveAssignmentMaxDays,
[ValidateRange(1, 365)]
[int]$EligibleAssignmentMaxDays,
[ValidatePattern('^[0-9a-fA-F-]{36}$')]
[string]$ApproverGroupId
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
if ($null -eq (Get-MgContext)) {
throw 'No Microsoft Graph session. Run Connect-MgGraph first.'
}
function New-RuleTarget {
param([string]$Caller, [string]$Level)
@{
'@odata.type' = 'microsoft.graph.unifiedRoleManagementPolicyRuleTarget'
caller = $Caller
operations = @('All')
level = $Level
inheritableSettings = @()
enforcedSettings = @()
}
}
foreach ($name in $RoleName) {
$escaped = $name.Replace("'", "''")
$role = @(Get-MgRoleManagementDirectoryRoleDefinition -Filter "displayName eq '$escaped'")
if ($role.Count -ne 1) { throw "Role not found or not unique: $name" }
$filter = "scopeId eq '/' and scopeType eq 'DirectoryRole' and roleDefinitionId eq '$($role[0].Id)'"
$assignment = @(Get-MgPolicyRoleManagementPolicyAssignment -Filter $filter -ExpandProperty 'policy($expand=rules)')
if ($assignment.Count -eq 0) { throw "No PIM policy found for $name" }
$policyId = $assignment[0].PolicyId
$authContextOn = $false
foreach ($rule in @($assignment[0].Policy.Rules)) {
if ($rule.Id -eq 'AuthenticationContext_EndUser_Assignment' -and $rule.AdditionalProperties.ContainsKey('isEnabled')) {
$authContextOn = ($rule.AdditionalProperties['isEnabled'] -eq $true)
}
}
$enabledRules = @('Justification')
if ($authContextOn) { Write-Warning "$name uses an authentication context on activation; MFA is left to that policy." }
else { $enabledRules += 'MultiFactorAuthentication' }
if ($RequireTicket) { $enabledRules += 'Ticketing' }
$updates = New-Object System.Collections.Generic.List[object]
$updates.Add([pscustomobject]@{
RuleId = 'Expiration_EndUser_Assignment'
Action = "Set activation maximum duration to $ActivationMaxHours hours"
Body = @{
'@odata.type' = '#microsoft.graph.unifiedRoleManagementPolicyExpirationRule'
id = 'Expiration_EndUser_Assignment'
isExpirationRequired = $true
maximumDuration = "PT$($ActivationMaxHours)H"
target = New-RuleTarget -Caller 'EndUser' -Level 'Assignment'
}
})
$updates.Add([pscustomobject]@{
RuleId = 'Enablement_EndUser_Assignment'
Action = "Require $($enabledRules -join ', ') on activation"
Body = @{
'@odata.type' = '#microsoft.graph.unifiedRoleManagementPolicyEnablementRule'
id = 'Enablement_EndUser_Assignment'
enabledRules = $enabledRules
target = New-RuleTarget -Caller 'EndUser' -Level 'Assignment'
}
})
if ($ActiveAssignmentMaxDays) {
$updates.Add([pscustomobject]@{
RuleId = 'Expiration_Admin_Assignment'
Action = "Require active assignments to expire after $ActiveAssignmentMaxDays days"
Body = @{
'@odata.type' = '#microsoft.graph.unifiedRoleManagementPolicyExpirationRule'
id = 'Expiration_Admin_Assignment'
isExpirationRequired = $true
maximumDuration = "P$($ActiveAssignmentMaxDays)D"
target = New-RuleTarget -Caller 'Admin' -Level 'Assignment'
}
})
}
if ($EligibleAssignmentMaxDays) {
$updates.Add([pscustomobject]@{
RuleId = 'Expiration_Admin_Eligibility'
Action = "Require eligible assignments to expire after $EligibleAssignmentMaxDays days"
Body = @{
'@odata.type' = '#microsoft.graph.unifiedRoleManagementPolicyExpirationRule'
id = 'Expiration_Admin_Eligibility'
isExpirationRequired = $true
maximumDuration = "P$($EligibleAssignmentMaxDays)D"
target = New-RuleTarget -Caller 'Admin' -Level 'Eligibility'
}
})
}
if ($ApproverGroupId) {
$updates.Add([pscustomobject]@{
RuleId = 'Approval_EndUser_Assignment'
Action = "Require approval by the members of group $ApproverGroupId"
Body = @{
'@odata.type' = '#microsoft.graph.unifiedRoleManagementPolicyApprovalRule'
id = 'Approval_EndUser_Assignment'
target = New-RuleTarget -Caller 'EndUser' -Level 'Assignment'
setting = @{
'@odata.type' = 'microsoft.graph.approvalSettings'
isApprovalRequired = $true
isApprovalRequiredForExtension = $false
isRequestorJustificationRequired = $true
approvalMode = 'SingleStage'
approvalStages = @(
@{
approvalStageTimeOutInDays = 1
isApproverJustificationRequired = $true
escalationTimeInMinutes = 0
isEscalationEnabled = $false
primaryApprovers = @(
@{ '@odata.type' = '#microsoft.graph.groupMembers'; groupId = $ApproverGroupId }
)
escalationApprovers = @()
}
)
}
}
})
}
foreach ($update in $updates) {
if ($PSCmdlet.ShouldProcess("$name ($policyId)", $update.Action)) {
Update-MgPolicyRoleManagementPolicyRule -UnifiedRoleManagementPolicyId $policyId -UnifiedRoleManagementPolicyRuleId $update.RuleId -BodyParameter $update.Body -Confirm:$false | Out-Null
[pscustomobject]@{ Role = $name; Rule = $update.RuleId; Change = $update.Action; Status = 'Updated' }
}
}
}
Preview the changes for Privileged Role Administrator:
.\Set-EntraPimRoleSettings.ps1 -RoleName 'Privileged Role Administrator' -ActivationMaxHours 2 -RequireTicket -ActiveAssignmentMaxDays 15 -ApproverGroupId '00000000-0000-0000-0000-000000000000' -WhatIf
What if: Performing the operation "Set activation maximum duration to 2 hours" on target "Privileged Role Administrator (DirectoryRole_00000000-0000-0000-0000-000000000000_00000000-0000-0000-0000-000000000000)".
What if: Performing the operation "Require Justification, MultiFactorAuthentication, Ticketing on activation" on target "Privileged Role Administrator (DirectoryRole_00000000-0000-0000-0000-000000000000_00000000-0000-0000-0000-000000000000)".
What if: Performing the operation "Require active assignments to expire after 15 days" on target "Privileged Role Administrator (DirectoryRole_00000000-0000-0000-0000-000000000000_00000000-0000-0000-0000-000000000000)".
What if: Performing the operation "Require approval by the members of group 00000000-0000-0000-0000-000000000000" on target "Privileged Role Administrator (DirectoryRole_00000000-0000-0000-0000-000000000000_00000000-0000-0000-0000-000000000000)".
Run it again without -WhatIf to apply the changes. Approvers can't approve their own requests, and Microsoft recommends at least two approvers, so give the approver group two or more members who don't activate the same role. The audit log records each change as the Update role setting in PIM activity, which the PIM role settings rules watch.
Step 3: Assign eligible roles and convert standing access
New administrators start as eligible, and existing permanent assignments move to time-bound eligible ones. Microsoft's deployment plan puts every Global Administrator and Security Administrator first, then the other roles labeled privileged.
Assign an eligible role in the portal
- Sign in to the Microsoft Entra admin center as at least a Privileged Role Administrator.
- Browse to ID Governance > Privileged Identity Management > Microsoft Entra roles, then select Roles.
- Select Add assignments, then Select a role. Choose the role and the member (a user or a group) and select Next.
- In Assignment type, select Eligible. Set a start and end date for a time-bound assignment, then select Assign.
A group can hold a Microsoft Entra role only if it was created as role-assignable. A guest who receives a built-in role gains the same permissions as a member user, so avoid it.
Convert permanent active assignments to eligible
For Microsoft Entra roles, PIM has a preview experience for this: Assignments > Active assignments, select the assignments, Manage Assignments, change the type to Eligible and save. Exclude the emergency access accounts. Review the Global Administrator safeguards first: PIM blocks removal of the last active Global Administrator assignment.
The same change in Microsoft Graph PowerShell takes two requests. Create the eligibility first, then remove the active assignment, so the person is never left without a way to work. Both cmdlets support -WhatIf. This needs RoleManagement.ReadWrite.Directory and the Privileged Role Administrator role; Microsoft's Graph PowerShell PIM tutorial shows the same request shapes.
Connect-MgGraph -Scopes 'RoleManagement.ReadWrite.Directory'
$principalId = '00000000-0000-0000-0000-000000000000'
$role = Get-MgRoleManagementDirectoryRoleDefinition -Filter "displayName eq 'Exchange Administrator'"
$eligibility = @{
Action = 'adminAssign'
Justification = 'Convert standing access to eligible, change CHG-1234'
RoleDefinitionId = $role.Id
DirectoryScopeId = '/'
PrincipalId = $principalId
ScheduleInfo = @{
StartDateTime = (Get-Date).ToUniversalTime()
Expiration = @{ Type = 'afterDateTime'; EndDateTime = (Get-Date).ToUniversalTime().AddDays(180) }
}
}
New-MgRoleManagementDirectoryRoleEligibilityScheduleRequest -BodyParameter $eligibility -WhatIf
$removeActive = @{
Action = 'adminRemove'
Justification = 'Convert standing access to eligible, change CHG-1234'
RoleDefinitionId = $role.Id
DirectoryScopeId = '/'
PrincipalId = $principalId
}
New-MgRoleManagementDirectoryRoleAssignmentScheduleRequest -BodyParameter $removeActive -WhatIf
Drop -WhatIf to apply each request, and check that the first one returns Status : Provisioned before you send the second. If the role's settings require an expiry, Microsoft Graph rejects a request without an end date with 400 Bad Request, so keep the end date within the role's maximum.
Step 4: Activate roles and approve requests
An eligible administrator activates the role for the task, inside the limits the role settings allow. In the Microsoft Entra admin center, browse to ID Governance > Privileged Identity Management > My roles, select Microsoft Entra roles, then Activate on the role. Complete Additional verification required if prompted, enter the Reason, and select Activate. Microsoft also offers activation in the My Access portal, in preview as of November 2026.
From PowerShell, the administrator sends a selfActivate request for their own object ID. Complete MFA when you open the session: Microsoft's API reference requires a session in which you were challenged for MFA when you activate, update, renew or extend your own assignment.
Connect-MgGraph -Scopes 'RoleAssignmentSchedule.ReadWrite.Directory', 'RoleManagement.Read.Directory', 'User.Read'
$me = Get-MgUser -UserId (Get-MgContext).Account
$role = Get-MgRoleManagementDirectoryRoleDefinition -Filter "displayName eq 'Exchange Administrator'"
$activation = @{
Action = 'selfActivate'
PrincipalId = $me.Id
RoleDefinitionId = $role.Id
DirectoryScopeId = '/'
Justification = 'Update transport rule, ticket INC-2231'
ScheduleInfo = @{
StartDateTime = (Get-Date).ToUniversalTime()
Expiration = @{ Type = 'AfterDuration'; Duration = 'PT1H' }
}
TicketInfo = @{ TicketNumber = 'INC-2231'; TicketSystem = 'ServiceDesk' }
}
New-MgRoleManagementDirectoryRoleAssignmentScheduleRequest -BodyParameter $activation
When the role requires approval, approvers see the request under ID Governance > Privileged Identity Management > Approve requests. They have 24 hours to act, and the window isn't configurable; after that the user must send a new request. The first approver who approves or denies resolves the request, approvers can't approve their own requests, and service principals can't approve.
PIM adds the active assignment within seconds of activation and removes it within seconds of deactivation, but an application that cached the user's roles may lag behind. A role can't be deactivated within five minutes of activation.
Step 5: Extend PIM to groups and Azure resource roles
PIM covers Microsoft Entra roles, PIM for Groups and Azure resource roles, each with its own assignments and settings. Protecting only directory roles leaves standing access elsewhere.
PIM for Groups
PIM for Groups makes membership or ownership of a security group or Microsoft 365 group eligible, with one policy for each. Dynamic membership groups and groups synchronized from on-premises can't be enabled.
- For a group that elevates into Microsoft Entra roles, require approval on eligible membership. Microsoft warns that otherwise a less privileged administrator could reset a member's credentials and activate on their behalf.
- Make such groups role-assignable. Only Global Administrator, Privileged Role Administrator or the group owner can manage a role-assignable group, and changing its members' credentials takes at least Privileged Authentication Administrator. A tenant can have at most 500 role-assignable groups.
- For roles with SharePoint, Exchange or Microsoft Purview portal permissions, use PIM for Microsoft Entra roles directly. Microsoft notes that activating them through group membership can take significant time.
Azure resource roles
Owner and User Access Administrator are just as dangerous at subscription or management group scope. Browse to ID Governance > Privileged Identity Management > Azure resources, pick the management group, subscription, resource group or resource, then Roles > Add assignments. Microsoft's Azure resource roles article describes each field.
- Settings are per role and per resource, and a subscription's settings aren't inherited by its resource groups. Configure each scope you protect.
- Microsoft's deployment plan says to manage every subscription Owner and User Access Administrator with PIM.
- A Global Administrator can elevate access to manage all Azure subscriptions, which is one more reason to keep that role eligible. The elevate access rules cover the elevation, and the privileged Azure role assignment rules cover new grants.
- Service principals, managed identities included, can't be eligible. Their standing Azure roles stay outside the activation model, and our Azure SQL managed identity research shows how far such an identity can reach. Keep those roles narrow.
Step 6: Turn on access reviews and PIM alerts
Access reviews remove eligibility that nobody needs anymore, and PIM alerts flag risky patterns such as roles assigned outside PIM.
Configure PIM security alerts
Open ID Governance > Privileged Identity Management > Microsoft Entra roles > Alerts > Setting. Microsoft's security alerts article lists these alerts, among others; only Global Administrator, Privileged Role Administrator, Global Reader, Security Administrator and Security Reader can read them.
| Alert | Severity | What to do |
|---|---|---|
| Roles are being assigned outside of Privileged Identity Management | High | Enable it with its email; remove each assignment you can't explain |
| Potential stale accounts in a privileged role | Medium | Set the number of days (1 to 365) and remove the role from unused accounts |
| There are too many Global Administrators | Low | Set the count and percentage thresholds, then move people to narrower roles |
| Roles don't require multifactor authentication for activation | Low | Require MFA or an authentication context on every role |
| Administrators aren't using their privileged roles | Low | Remove eligibility nobody activates |
| Roles are being activated too frequently | Low | Review the user and the activation duration |
Schedule access reviews of privileged roles
An access review asks reviewers to confirm each assignment. Creating one for Microsoft Entra roles needs at least Privileged Role Administrator; for Azure resources, Owner or User Access Administrator. Microsoft's access review article covers each option.
- Browse to ID Governance > Privileged Identity Management > Microsoft Entra roles, then Microsoft Entra roles under Manage > Access reviews > New.
- Set Frequency to Quarterly or Monthly, and pick the privileged roles under Review role membership. Each selected role becomes its own review.
- Choose all active and eligible assignments, and reviewers other than the members themselves.
- Under Upon completion settings, set Auto apply results to resource to Enable and If reviewers don't respond to Remove access for Tier 0 roles.
A review of a role held by a role-assignable group shows the group, not its members, so review the group membership separately.
Verify
Verify at three levels: the assignments, the settings and a real activation.
| Check | Expected result |
|---|---|
Get-EntraPimRoleAssignmentAudit.ps1 -PrivilegedOnly |
PermanentActiveToReview is 0; only the emergency access accounts show Expected: emergency access |
Get-EntraPimRoleSettings.ps1 for Tier 0 roles |
Findings is empty, apart from permanent active assignments allowed on Global Administrator if you kept that option for emergency access accounts |
| Test activation by a pilot administrator | MFA or the authentication context prompts, the approver receives the request, and the role ends when the chosen activation duration runs out |
| Microsoft Entra roles > Resource audit | The assignments, the activation and the setting changes appear; this view keeps 30 days |
| Microsoft Entra audit log | An Add member to role completed (PIM activation) record for the test, with your justification |
| PIM alerts | No Roles are being assigned outside of Privileged Identity Management alert after the cleanup |
Roll back
Most PIM changes can be undone in the portal or with the same Graph requests; a lapsed license can't.
| Change | How to roll back | Notes |
|---|---|---|
| Eligible conversion | Select the eligible assignment and choose Make active, as Microsoft's deployment plan describes, or send an adminAssign request to the assignment cmdlet |
The role's settings must allow the active duration you choose |
| Role settings | Edit Role settings in the portal back to the values in your CSV export | The JSON baseline from Step 2 holds every rule's previous values; Set-EntraPimRoleSettings.ps1 can't turn requirements off or allow permanent assignments again |
| Approval requirement | Clear Require approval to activate in the role settings | Do this first if approvers become unavailable |
| Authentication context | Switch On activation, require back to Azure MFA | Remove the Conditional Access policy only after that |
| PIM for Groups | Make members active | A group can't be taken out of PIM management once it's managed; check the group's role assignments afterward |
| License lapse | Can't be undone | Microsoft says eligible assignments are removed, time-bound active assignments become permanent active, and PIM settings are removed |
Keep the Step 1 exports as the record of who held which role before the change.
Monitor and detect
Watch three things in the Microsoft Entra audit log: assignments that bypass PIM, Tier 0 activations, and changes to PIM settings and alerts. PIM's Resource audit view keeps 30 days, so route the audit log to a Log Analytics workspace with a diagnostic setting.
| Activity (audit log) | What it means | Related pages |
|---|---|---|
| Add member to role outside of PIM (permanent) | A permanent assignment made outside PIM | Privileged directory role assignment rules |
| Add member to role in PIM completed (permanent) | A permanent active assignment made through PIM | Same rules |
| Add eligible member to role in PIM completed (permanent) | Eligibility with no end date | Same rules |
| Add member to role completed (PIM activation) | An activation finished and the role is active | Same rules, which include a Tier 0 activation rule |
| Update role setting in PIM | A role's PIM settings changed | Detection rules for weakened PIM settings |
| Disable PIM alert and Update PIM alert setting | A PIM security alert was turned off or changed | Same rules |
Microsoft's audit activity reference lists all seven activity names under the RoleManagement category, and most of them under ResourceManagement and GroupManagement as well. Activations that wait for approval or start later can carry different CorrelationId values; Microsoft points to roleAssignmentRequestId in AdditionalDetails to tie the records together.
The first query returns new permanent active assignments with the role name. It reads the AuditLogs table and the Role.DisplayName modified property that Microsoft's security operations guidance refers to.
// New permanent active Microsoft Entra role assignments, made inside or outside PIM.
// Needs Microsoft Entra audit logs in the AuditLogs table (diagnostic setting).
AuditLogs
| where TimeGenerated > ago(7d)
| where OperationName in ("Add member to role outside of PIM (permanent)", "Add member to role in PIM completed (permanent)")
| where Result == "success"
| extend Actor = coalesce(tostring(InitiatedBy.user.userPrincipalName), tostring(InitiatedBy.app.displayName))
| mv-expand Target = TargetResources
| mv-expand Property = Target.modifiedProperties
| where tostring(Property.displayName) == "Role.DisplayName"
| extend RoleName = trim('"', tostring(Property.newValue))
| project TimeGenerated, OperationName, Actor, RoleName, CorrelationId
| order by TimeGenerated desc
The second query lists every change to PIM role settings and PIM alerts, successful or not.
// Changes to PIM role settings and PIM security alerts.
AuditLogs
| where TimeGenerated > ago(30d)
| where OperationName in ("Update role setting in PIM", "Disable PIM alert", "Update PIM alert setting")
| extend Actor = coalesce(tostring(InitiatedBy.user.userPrincipalName), tostring(InitiatedBy.app.displayName))
| mv-apply Target = TargetResources on (summarize Targets = make_set(tostring(Target.displayName)))
| project TimeGenerated, OperationName, Result, Actor, Targets, ResultReason, CorrelationId
| order by TimeGenerated desc
The third query counts Tier 0 activations per account and day; compare the accounts with your list of approved Tier 0 administrators.
// PIM activations of Tier 0 Microsoft Entra roles, per account and day.
let TierZeroRoles = dynamic(["Global Administrator", "Privileged Role Administrator", "Privileged Authentication Administrator"]);
AuditLogs
| where TimeGenerated > ago(14d)
| where OperationName == "Add member to role completed (PIM activation)"
| where Result == "success"
| where tostring(TargetResources) has_any (TierZeroRoles)
| extend Actor = coalesce(tostring(InitiatedBy.user.userPrincipalName), tostring(InitiatedBy.app.displayName))
| summarize Activations = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by Actor, Day = bin(TimeGenerated, 1d)
| order by Day desc, Activations desc
The queries select records by activity name (OperationName) alone, as the sample queries in Microsoft's PIM audit history article do. They don't filter on the Category column, which Microsoft's AuditLogs table reference describes as currently always Audit.
Troubleshooting
Most PIM problems come from session state, approval timing or settings that differ by role.
| Symptom | Cause | Fix |
|---|---|---|
| Activation doesn't prompt for MFA | The user already completed MFA earlier in the session | Use an authentication context with sign-in frequency Every time |
| The role is active but the app still denies access | The application cached the user's roles | Sign out and back in; wait for the app to refresh its token |
| A request expired without action | Approvers didn't respond within 24 hours | Submit a new request; add a second approver |
| Nobody can activate Global Administrator | Approval is required, all administrators are eligible and no approvers are set | Sign in with an emergency access account and set named approvers |
| Deactivate fails right after activation | A role can't be deactivated within five minutes of activation | Wait five minutes |
Microsoft Graph returns 400 Bad Request for a new assignment |
The request has no end date, but the role's settings require one | Add an end date within the role's maximum |
| Removing a Global Administrator assignment fails | PIM blocks removal of the last active Global Administrator assignment | Keep the emergency access accounts active, then remove the others |
| Exchange or SharePoint permissions arrive late after a group activation | Activation through group membership can take significant time for roles with those portal permissions | Make the role itself eligible with PIM for Microsoft Entra roles |
| Approval or MFA appears missing on a resource group | Azure settings aren't inherited from the subscription | Configure the role settings at each scope |
How Forestall helps
Forestall lists every Microsoft Entra ID role with the users, groups, service principals and devices that hold it. It marks objects that can compromise admin objects through an attack path as Shadow, which PIM settings alone don't show. It models Privileged Role Administrator, which can change role assignments and PIM role settings, as the AZ_PRIVILEGED_ROLE_ADMIN edge, and other built-in privileged roles as AZ_BUILTIN_PRIVILEGED_ROLE. Identity Attack Surface Management maps these identities and trust relationships across Active Directory, Entra ID and Azure without agents.
Frequently Asked Questions
What is the difference between eligible and active assignments in PIM?
In Microsoft Entra PIM, an eligible assignment gives a user the right to activate a role when needed, after the checks the role's settings require, such as MFA, a justification or approval. An active assignment works at once, with no activation. Both can be permanent or time-bound. Microsoft recommends keeping zero permanent active assignments except for emergency access accounts, so most administrators should hold time-bound eligible assignments.
What license do I need for Microsoft Entra PIM?
Microsoft Entra PIM needs Microsoft Entra ID P2 or Microsoft Entra ID Governance licenses. They must cover users with eligible or time-bound assignments, PIM for Groups members and owners, approvers, and users in access reviews or performing them. Microsoft Entra ID P2 is included in Microsoft 365 E5 and E7. Microsoft says Microsoft Entra ID Governance licenses don't need to be assigned to each user, but their number must cover every member user in scope (as of November 2026).
Is Azure PIM the same as Microsoft Entra PIM?
Yes, Azure PIM and Azure AD PIM are names still used for Microsoft Entra Privileged Identity Management, because Azure AD is now called Microsoft Entra ID. The same service manages Microsoft Entra roles, Azure resource roles such as Owner and User Access Administrator, and PIM for Groups. You configure all three under ID Governance in the Microsoft Entra admin center, each with its own assignments and role settings.
How long can a PIM activation last?
The PIM activation maximum duration is a per-role setting from one to 24 hours. The user picks a duration up to that maximum when activating, and the role expires at the end unless the user deactivates it earlier. Microsoft's deployment plan uses one hour for Global Administrator as an example. A role can't be deactivated within five minutes of activation.
Should break glass accounts use PIM?
Break glass accounts should not depend on PIM activation. Microsoft recommends two or more cloud-only emergency access accounts whose Global Administrator assignment in PIM is permanent active, not eligible. They should use phishing-resistant authentication that differs from your daily admin accounts and be excluded from Conditional Access policies that block sign-in. Alert on every sign-in and test them at least every 90 days.
What happens to PIM when the license expires?
PIM features stop working when the Microsoft Entra ID P2, Microsoft Entra ID Governance or trial license expires. Microsoft says permanent active assignments stay, time-bound active assignments become permanent active, and eligible assignments are removed. PIM settings are removed, ongoing access reviews of Microsoft Entra roles end, and PIM stops sending emails. Renew licenses before they lapse.
Related guides
- Set up break glass accounts in Entra ID: the emergency access accounts that keep their permanent active Global Administrator assignment.
- Harden Entra Connect and Cloud Sync: protect the hybrid identity path behind Hybrid Identity Administrator and synchronized accounts.
- Investigate risky users in Entra ID Protection: respond when an eligible administrator's account shows risk.
- Block device code flow with Conditional Access: close a sign-in path that phishing campaigns use against administrators.
- Microsoft Entra ID security checklist for beginners: where PIM fits among the other tenant controls, together with privileged access management and least privilege access.
References
- What is Microsoft Entra Privileged Identity Management? (Microsoft Learn)
- Microsoft Entra ID Governance licensing fundamentals (Microsoft Learn)
- Plan a Privileged Identity Management deployment (Microsoft Learn)
- Configure Microsoft Entra role settings in Privileged Identity Management (Microsoft Learn)
- Assign Microsoft Entra roles in Privileged Identity Management using Microsoft Graph PowerShell (Microsoft Learn)
- Privileged Identity Management (PIM) for Groups (Microsoft Learn)
- Assign Azure resource roles in Privileged Identity Management (Microsoft Learn)
- Security alerts for Microsoft Entra roles in PIM (Microsoft Learn)
- Create an access review of Azure resource and Microsoft Entra roles in PIM (Microsoft Learn)
- Microsoft Entra audit log categories and activities (Microsoft Learn)
- Manage emergency access admin accounts (Microsoft Learn)
- Account Manipulation: Additional Cloud Roles, T1098.003 (MITRE ATT&CK)
See your identity exposure clearly.
Start with a 1-day Proof of Value in your own environment.