Share via

Getting a list of users whole PIM role assignments are about to expire

MrFlinstone 761 Reputation points
2026-06-19T09:48:18.2933333+00:00

I would like to know if its possible to get a list of users whose PIM directory role assignments are about to expire, usually an email gets sent with 14 days to go, but keen to understand if there is a powershell script that can be executed to show eligible role assignments that are about to expire

Microsoft Security | Microsoft Entra | Microsoft Entra ID

1 answer

Sort by: Most helpful
  1. AI answer

    2026-06-19T09:48:33.2433333+00:00

    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:

    1. Query eligible role assignment schedule instances for directory roles.
    2. Filter where scheduleInfo (or equivalent end date property) is within the next 14 days.
    3. 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:

    1. In the Azure portal, open Access control (IAM) for the resource (for example, a subscription).
    2. Go to Role assignments.
    3. 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:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.