azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

[Doc]: Update-AzRoleManagementPolicy error when running provided sample code : Unable to find type [RoleManagementPolicyExpirationRule]

Open kayasax opened this issue 2 years ago • 8 comments

Description

Hi, trying to run example 1 from https://learn.microsoft.com/en-us/powershell/module/az.resources/update-azrolemanagementpolicy?view=azps-9.5.0&tryIt=true#code-try-2 et getting the following error (cloudshell or powershell) InvalidOperation: Unable to find type [RoleManagementPolicyExpirationRule]

image

kayasax avatar Mar 23 '23 10:03 kayasax

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @aperezcloud, @kenieva.

Issue Details

Description

Hi, trying to run example 1 from https://learn.microsoft.com/en-us/powershell/module/az.resources/update-azrolemanagementpolicy?view=azps-9.5.0&tryIt=true#code-try-2 et getting the following error (cloudshell or powershell) InvalidOperation: Unable to find type [RoleManagementPolicyExpirationRule]

image

Author: kayasax
Assignees: -
Labels:

Policy, Service Attention, customer-reported

Milestone: -

ghost avatar Mar 26 '23 16:03 ghost

Thanks for reporting @kayasax let me route this to the service team.

isra-fel avatar Mar 26 '23 16:03 isra-fel

Thanks for reporting, @kayasax. Let me route this to the service team.

I encountered the same issue today. Are there any updates?

pschonfeld avatar Mar 07 '24 16:03 pschonfeld

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @aperezcloud, @kenieva.

This issue has also been reported and a workaround provided here: https://github.com/Azure/azure-powershell/issues/18781.

walchst avatar Mar 12 '24 22:03 walchst

Guys, since the issue is still ongoing i've updated the docs with the workaround.

B-Oudehinken avatar Sep 10 '25 07:09 B-Oudehinken

My PIM script which was working fine for quite some time is now broken with the update to Az PowerShell v15 using Az.Resources v9.x.

Image

@B-Oudehinken the updated docs with the workaround is now broken as well. Won't work with Az PowerShell 15.x.

This whole PIM topic is very frustrating and badly documented.

svwie avatar Dec 08 '25 13:12 svwie

Found a working solution with Azure PowerShell v15.x / Az.Resources 9.x. Had to remove the preview API parts and no more namespace for ruleType definitions.

Here are a few snippets which should help you get started with the latest release.

This will apply to all kind of Rules. Just change RoleManagementPolicyExpirationRule to whatever you are working on (ExpirationRule, EnablementRule or NotificationRule)

$expirationAdminEligibility = [Microsoft.Azure.PowerShell.Cmdlets.Resources.Authorization.Models.RoleManagementPolicyExpirationRule]@{
    isExpirationRequired = "false";
    maximumDuration = "P1Y";
    id = "Expiration_Admin_Eligibility";
    ruleType = ("RoleManagementPolicyExpirationRule");
    targetCaller = "Admin";
    targetOperation = @('All');
    targetLevel = "Eligibility";
    targetObject = $null;
    targetInheritableSetting = $null;
    targetEnforcedSetting = $null;
}

Put all the configured rules together and update the role.

$rules = [Microsoft.Azure.PowerShell.Cmdlets.Resources.Authorization.Models.IRoleManagementPolicyRule[]]@($expirationAdminEligibility,$expirationAdminAssignment,$notificationAdminAdminEligibility,$notificationAdminAdminAssignment,$notificationAdminEndUserAssignment,$expirationEndUserAssignment,$enablementAdminAssignment,$enablementEndUserAssignment)

Update-AzRoleManagementPolicy -Scope $scope -Name $roleName.Name -Rule $rules

Please do some proper testing and update the documentation accordingly. Following the current v15 docs will end up with error messages.

svwie avatar Dec 09 '25 06:12 svwie