A cloud-based identity and access management service for securing user authentication and resource access
Yes. PIM already sends emails 14 days before expiration, but eligible and time‑bound assignments can also be queried via PowerShell.
There are two main approaches, depending on whether the roles are Azure resource roles (Azure RBAC) or Microsoft Entra roles.
1. Azure resource roles (Azure RBAC via PIM)
Use the Azure PowerShell PIM schedule cmdlets against the relevant scope and filter by end date.
Example for a subscription scope:
$subscriptionId = "<subscriptionId>"
$cutoff = (Get-Date).AddDays(14)
# Eligible role assignments
$eligible = Get-AzRoleEligibilitySchedule -Scope "/subscriptions/$subscriptionId" |
Where-Object { $_.EndDateTime -ne $null -and $_.EndDateTime -le $cutoff }
# Active time-bound role assignments (exclude permanent)
$activeTimeBound = Get-AzRoleAssignmentSchedule -Scope "/subscriptions/$subscriptionId" |
Where-Object { $_.EndDateTime -ne $null -and $_.EndDateTime -le $cutoff }
$expiring = $eligible + $activeTimeBound
$expiring | Select-Object PrincipalId, RoleDefinitionName, StartDateTime, EndDateTime, Scope
Get-AzRoleEligibilitySchedule returns eligible assignments; Get-AzRoleAssignmentSchedule returns active assignments. Filtering on EndDateTime within the next 14 days gives the list of users whose PIM-backed Azure RBAC roles are about to expire.
2. Microsoft Entra roles (directory roles via PIM)
For Microsoft Entra roles, use Microsoft Graph PowerShell PIM APIs. Role assignment requests and schedules support actions such as AdminExtend, AdminRenew, SelfExtend, and SelfRenew, and include schedule information.
Conceptually, the steps are:
- Query eligible role assignment schedule instances for directory roles.
- Filter where
scheduleInfo(or equivalent end date property) is within the next 14 days. - Project principal, role definition, and end date.
Example pattern (principal filter shown in context; extend it to all principals and add date filtering):
# Example from context to list eligible role assignments for a user
Get-MgRoleManagementDirectoryRoleEligibilityScheduleInstance `
-Filter "principalId eq '<user-object-id>'" | Format-List
To build a report of expiring assignments, iterate over schedule instances, inspect their schedule/end date, and filter to those expiring within 14 days. The same model supports actions SelfExtend and SelfRenew, which are what users invoke when they extend/renew expiring or expired assignments.
3. Portal alternative (quick check)
If a one-off check is sufficient, the Azure portal can list eligible and time‑bound Azure RBAC assignments:
- In the Azure portal, open Access control (IAM) for the resource (for example, a subscription).
- Go to Role assignments.
- Group/sort by State and look for assignments that are not Active permanent.
This view shows eligible and time‑bound assignments; you can visually identify those nearing expiration.
References:
- Eligible and time-bound role assignments in Azure RBAC
- Assign Microsoft Entra roles in Privileged Identity Management using Microsoft Graph PowerShell
- Extend or renew Microsoft Entra role assignments in Privileged Identity Management
- Extend or renew Azure resource role assignments in Privileged Identity Management
- Email notifications in PIM