Azure / Azure/azure-powershell
AZ Module does not find the class module when trying to execute Update-AzRoleManagementPolicy cmdlet
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 3d 14h
- Merged PRs (30d)
- 54
Description
### Description
I am trying to update Azure PIM role policy settings with Update-AzRoleManagementPolicy since this seems easier than working with ARM templates. However, when I go to execute the examples found here https://docs.microsoft.com/en-us/powershell/module/az.resources/update-azrolemanagementpolicy?view=azps-8.0.0 they do not work and throw an error that the class RoleManagementPolicyExpirationRule cannot be found. I have tried this both in my Azure gov and public tenants with the same results.
### Issue script & Debug output
```PowerShell
$scope = "/subscriptions/38ab2ccc-3747-4567-b36b-9478f5602f0d/"
$expirationRule = [RoleManagementPolicyExpirationRule]@{
isExpirationRequired = "false";
maximumDuration = "P180D";
id = "Expiration_Admin_Eligibility";
ruleType = [RoleManagementPolicyRuleType]("RoleManagementPolicyExpirationRule");
targetCaller = "Admin";
targetOperation = @('All');
targetLevel = "Eligibility";
targetObject = $null;
targetInheritableSetting = $null;
targetEnforcedSetting = $null;
}
$rules = [IRoleManagementPolicyRule[]]@($expirationRule)
Update-AzRoleManagementPolicy -Scope $scope -Name "33b520ea-3544-4abc-8565-3588deb8e68e" -Rule $rules
```
### Environment data
```PowerShell
Name Value
---- -----
PSVersion 5.1.22000.653
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22000.653
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
```
### Module versions
```PowerShell
Version Name
------- ----
8.0.0 Az
2.8.0 Az.Accounts
1.1.2 Az.Advisor
4.1.0 Az.Aks
1.1.4 Az.AnalysisServices
3.0.0 Az.ApiManagement
1.1.0 Az.AppConfiguration
2.0.0 Az.ApplicationInsights
1.0.0 Az.Attestation
1.7.3 Az.Automation
3.2.0 Az.Batch
2.0.0 Az.Billing
2.1.0 Az.Cdn
1.1.0 Az.CloudService
1.11.0 Az.CognitiveServices
4.27.0 Az.Compute
3.1.0 Az.ContainerInstance
3.0.0 Az.ContainerRegistry
1.8.0 Az.CosmosDB
1.1.0 Az.DataBoxEdge
1.2.0 Az.Databricks
1.16.7 Az.DataFactory
1.0.2 Az.DataLakeAnalytics
1.3.0 Az.DataLakeStore
1.0.1 Az.DataShare
1.1.0 Az.DeploymentManager
3.1.0 Az.DesktopVirtualization
1.0.2 Az.DevTestLabs
1.1.2 Az.Dns
1.3.0 Az.EventGrid
2.0.0 Az.EventHub
1.9.0 Az.FrontDoor
4.0.3 Az.Functions
5.0.1 Az.HDInsight
2.0.0 Az.HealthcareApis
2.7.4 Az.IotHub
4.5.0 Az.KeyVault
2.1.0 Az.Kusto
1.5.0 Az.LogicApp
1.1.3 Az.MachineLearning
1.2.0 Az.Maintenance
1.0.0 Az.ManagedServiceIdentity
3.0.0 Az.ManagedServices
1.0.2 Az.MarketplaceOrdering
1.1.1 Az.Media
1.1.2 Az.Migrate
3.0.1 Az.Monitor
1.0.0 Az.MySql
4.17.0 Az.Network
1.1.1 Az.NotificationHubs
3.1.0 Az.OperationalInsights
1.5.0 Az.PolicyInsights
1.1.0 Az.PostgreSql
1.1.2 Az.PowerBIEmbedded
1.0.3 Az.PrivateDns
5.4.0 Az.RecoveryServices
1.6.0 Az.RedisCache
1.0.0 Az.RedisEnterpriseCache
1.0.3 Az.Relay
1.1.0 Az.ResourceMover
6.0.0 Az.Resources
1.3.0 Az.Security
1.1.0 Az.SecurityInsights
1.9.0 Az.ServiceBus
3.0.2 Az.ServiceFabric
1.4.1 Az.SignalR
3.9.0 Az.Sql
1.1.0 Az.SqlVirtualMachine
1.1.1 Az.StackHCI
4.6.0 Az.Storage
1.7.0 Az.StorageSync
2.0.0 Az.StreamAnalytics
1.0.0 Az.Support
1.4.0 Az.Synapse
1.1.0 Az.TrafficManager
2.11.2 Az.Websites
```
### Error output
```PowerShell
Message : Unable to find type [IRoleManagementPolicyRule].
StackTrace : at System.Management.Automation.TypeOps.ResolveTypeName(ITypeName typeName, IScriptExtent errorPos)
at System.Management.Automation.TypeOps.ResolveTypeName(ITypeName typeName, IScriptExtent errorPos)
at System.Management.Automation.Interpreter.FuncCallInstruction`3.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Exception : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line : $rules = [IRoleManagementPolicyRule[]]@($expirationRule)
Position : At line:14 char:11
+ $rules = [IRoleManagementPolicyRule[]]@($expirationRule)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : -1
Message : Unable to find type [RoleManagementPolicyExpirationRule].
StackTrace : at System.Management.Automation.TypeOps.ResolveTypeName(ITypeName typeName, IScriptExtent errorPos)
at System.Management.Automation.Interpreter.FuncCallInstruction`3.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Exception : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line : $expirationRule = [RoleManagementPolicyExpirationRule]@{
Position : At line:2 char:20
+ $expirationRule = [RoleManagementPolicyExpirationRule]@{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : -1
```
Contributor guide
Assessment
This issue has not been assessed yet.