A cloud-based identity and access management service for securing user authentication and resource access
Hey there! You can absolutely pull back upcoming expirations via PowerShell. The easiest approach is to use the Microsoft Graph PowerShell SDK to enumerate eligible PIM assignments in your tenant and then filter on the end date. Here’s a quick script you can run:
# Install & connect
Install-Module Microsoft.Graph -Scope CurrentUser -Force
Import-Module Microsoft.Graph
Connect-MgGraph -Scopes "RoleManagement.Read.Directory"
# Define window
$now = (Get-Date).ToUniversalTime()
$threshold = $now.AddDays(14)
# Grab all eligible role assignments and filter for those ending in the next 14 days
$expiring = Get-MgRoleManagementDirectoryRoleEligibilityScheduleInstance -All |
Where-Object {
$end = [datetime]$_.ScheduleInfo.EndDateTime
$end -gt $now -and $end -le $threshold
} |
Select-Object `
@{n='User'; e={$_.PrincipalDisplayName}},
@{n='Role'; e={$_.RoleDefinitionId}},
@{n='Expires';e={$_.ScheduleInfo.EndDateTime}}
# Output to screen (or export to CSV)
$expiring | Format-Table -AutoSize
# $expiring | Export-Csv expiring-pim-assignments.csv -NoTypeInformation
What this does:
- Connects to Microsoft Graph with PIM read rights.
- Pulls all eligible (time-bound) role assignments.
- Filters where the
EndDateTimeis between now and 14 days out. - Shows you the user, the role definition ID, and the exact expiry timestamp.
If you’re managing Azure Resource roles via PIM (instead of directory roles), you can do something similar with the Az module:
Install-Module Az.Resources -Scope CurrentUser -Force
Connect-AzAccount
Get-AzRoleEligibilitySchedule -Scope /subscriptions/<yourSubId> |
Where-Object {
$_.EndDateTime -ne $null -and
$_.EndDateTime -le (Get-Date).AddDays(14)
} |
Select-Object PrincipalName, RoleDefinitionName, EndDateTime
That will list all eligible RBAC assignments in the subscription that expire within the next 14 days.
Hope that gets you exactly the visibility you need!
References:
https://learn.microsoft.com/azure/role-based-access-control/pim-integration