Official Microsoft Learn path
The official guidance first resolves the policy assignment to learn the hidden policy ID, then instantiates multiple strongly-typed rules before calling Update-AzRoleManagementPolicy for each scope.
Connect-AzAccount
$scope = "/subscriptions/<subscriptionId>"
$roleDefinitionId = (Get-AzRoleDefinition -Name "Contributor").Id
# Microsoft Learn omits this lookup: find the policy GUID that backs the assignment
$assignment = Get-AzRoleManagementPolicyAssignment -Scope $scope |
Where-Object { $_.RoleDefinitionId -eq $roleDefinitionId }
$policyId = $assignment.PolicyId
$enablementRule = [Microsoft.Azure.PowerShell.Cmdlets.Resources.Authorization.Models.Api20201001Preview.RoleManagementPolicyEnablementRule]@{
enabledRules = @('MultiFactorAuthentication', 'Justification')
id = 'Enablement_EndUser_Assignment'
ruleType = [Microsoft.Azure.PowerShell.Cmdlets.Resources.Authorization.Support.RoleManagementPolicyRuleType]::RoleManagementPolicyEnablementRule
targetCaller = 'EndUser'
targetOperation = @('Activate')
targetLevel = 'Assignment'
}
$notificationRule = [Microsoft.Azure.PowerShell.Cmdlets.Resources.Authorization.Models.Api20201001Preview.RoleManagementPolicyNotificationRule]@{
notificationType = 'Email'
recipientType = 'Approver'
notificationRecipients = @('approver@contoso.com')
isDefaultRecipientsEnabled = 'false'
notificationLevel = 'Critical'
id = 'Notification_Approver_EndUser_Assignment'
ruleType = [Microsoft.Azure.PowerShell.Cmdlets.Resources.Authorization.Support.RoleManagementPolicyRuleType]::RoleManagementPolicyNotificationRule
targetCaller = 'EndUser'
targetOperation = @('Activate')
targetLevel = 'Assignment'
}
# Additional rules (for approvals, ticketing, etc.) require more typed objects.
$rules = [Microsoft.Azure.PowerShell.Cmdlets.Resources.Authorization.Models.Api20201001Preview.IRoleManagementPolicyRule[]]@(
$enablementRule,
$notificationRule
)
Update-AzRoleManagementPolicy -Scope $scope -Name $policyId -Rule $rules
Source: Update-AzRoleManagementPolicy (Az.Resources).
Extra work: Requiring approvers means creating an additional RoleManagementPolicyApprovalRule plus nested stage objects that reference each approver’s object ID.
Limitation: Administrators must discover the policy GUID up front, keep track of role definition IDs, and author each RoleManagementPolicy* object manually for every subscription.
The EasyPIM way
EasyPIM resolves the policy and pushes all requirements—MFA, justification prompts, mail notifications, and optional approvals—in a single command without building SDK objects.
$approver = Resolve-EasyPIMPrincipal -PrincipalIdentifier "approver@contoso.com"
Set-PIMAzureResourcePolicy `
-TenantId $tenantId `
-SubscriptionId $subscriptionId `
-RoleName "Contributor" `
-ActivationRequirement @("MultiFactorAuthentication", "Justification") `
-ApprovalRequired $true `
-Approvers @(@{ Id = $approver.Id; Name = $approver.DisplayName; Type = $approver.Type }) `
-Notification_Activation_Approver @{ isDefaultRecipientEnabled = "false"; notificationLevel = "Critical"; Recipients = @("approver@contoso.com") }
Apply identical settings to many roles or scopes by passing arrays to -RoleName or -Scope; EasyPIM discovers the policy IDs and loops the updates automatically.