Skip to content

Commit 37f7d98

Browse files
authored
Fix index out of range issue in Powershell (#25681)
1 parent e99abfa commit 37f7d98

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Resources/Resources/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Added null check and empty list check to the permissions object in the ToPSRoleDefinition method.
2223
* Added argument completer for `EnforcementMode`, `IdentityType`
2324
* `New-AzPolicyAssignment`
2425
* `New-AzPolicyExemption`

src/Resources/Resources/Models.Authorization/AuthorizationClientExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Microsoft.Azure.Commands.ActiveDirectory;
1717
using Microsoft.Azure.Management.Authorization.Models;
1818
using System;
19+
using System.Collections;
1920
using System.Collections.Generic;
2021
using System.Globalization;
2122
using System.Linq;
@@ -58,8 +59,8 @@ public static PSRoleDefinition ToPSRoleDefinition(this RoleDefinition role)
5859
AssignableScopes = role.AssignableScopes.ToList(),
5960
Description = role.Description,
6061
IsCustom = role.RoleType == CustomRole ? true : false,
61-
Condition = role?.Permissions?[0]?.Condition,
62-
ConditionVersion = role?.Permissions?[0]?.ConditionVersion
62+
Condition = (role.Permissions != null && role.Permissions.Count > 0) ? role.Permissions[0].Condition : null,
63+
ConditionVersion = (role.Permissions != null && role.Permissions.Count > 0) ? role.Permissions[0].ConditionVersion : null
6364
};
6465
}
6566

0 commit comments

Comments
 (0)