An Azure service that provides fine-grained access management for Azure resources, enabling you to grant users only the rights they need to perform their jobs.
Hello BANERJEE, SUBHAM,
To fetch all Azure resource role assignments in full detail, there is no single cmdlet that returns everything together. For Azure resource PIM, you need to combine:
-
Get-AzRoleAssignment→ regular Azure RBAC active / permanent assignments -
Get-AzRoleAssignmentSchedule→ PIM active assignments -
Get-AzRoleEligibilitySchedule→ PIM eligible assignments.
Also, if your requirement is to cover management group, resource group, and resource level, you must query each scope separately. A management group scope query returns assignments at the management group scope, but to collect assignments below it, you need to loop through the child subscriptions / RGs / resources and run the same cmdlets for each scope. The PIM schedule cmdlets support Azure resource scopes, including management group and resource scopes.
Recommended approach
- Get all standing active assignments using
Get-AzRoleAssignment - Get all PIM active assignments using
Get-AzRoleAssignmentSchedule - Get all PIM eligible assignments using
Get-AzRoleEligibilitySchedule - Filter out service principals / managed identities / break-glass / service accounts before remediation. Microsoft documents that eligible assignments cannot be created for applications, service principals, or managed identities.
# Example scopes
$scopes = @(
"/providers/Microsoft.Management/managementGroups/<mgId>",
"/subscriptions/<subId>",
"/subscriptions/<subId>/resourceGroups/<rgName>",
"/subscriptions/<subId>/resourceGroups/<rgName>/providers/<RP>/<type>/<name>"
)
$result = foreach ($scope in $scopes) {
# Permanent / active RBAC
Get-AzRoleAssignment -Scope $scope | Select-Object `
@{N='Source';E={'RBAC'}},
Scope,
RoleDefinitionName,
RoleDefinitionId,
ObjectId,
ObjectType,
DisplayName,
SignInName
# PIM Active
Get-AzRoleAssignmentSchedule -Scope $scope | Select-Object `
@{N='Source';E={'PIM-Active'}},
Scope,
RoleDefinitionId,
PrincipalId,
PrincipalType,
StartDateTime,
EndDateTime,
@{N='RoleDefinitionName';E={$_.ExpandedProperties.RoleDefinition.DisplayName}},
@{N='DisplayName';E={$_.ExpandedProperties.Principal.DisplayName}}
# PIM Eligible
Get-AzRoleEligibilitySchedule -Scope $scope | Select-Object `
@{N='Source';E={'PIM-Eligible'}},
Scope,
RoleDefinitionId,
PrincipalId,
PrincipalType,
StartDateTime,
EndDateTime,
@{N='RoleDefinitionName';E={$_.ExpandedProperties.RoleDefinition.DisplayName}},
@{N='DisplayName';E={$_.ExpandedProperties.Principal.DisplayName}}
}
$result | Export-Csv .\AzureResourcePIMRoles.csv -NoTypeInformation
``
If you want to convert active/permanent assignments to Eligible
The supported method is:
- create an eligible assignment using
New-AzRoleEligibilityScheduleRequest - then remove the existing standing assignment. For active PIM assignments, removal is done through
New-AzRoleAssignmentScheduleRequest -RequestType AdminRemove. Important note:
Please do this in audit mode first, because PIM policy may restrict whether permanent eligible assignments are allowed, and you should keep service principals, managed identities, service accounts, and break-glass accounts excluded from conversion.