@@ -187,11 +187,17 @@ public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions
187
187
parameters . PrincipalId = string . IsNullOrEmpty ( options . ADObjectFilter . Id ) ? adObject . Id : Guid . Parse ( options . ADObjectFilter . Id ) ;
188
188
}
189
189
190
- result . AddRange ( AuthorizationManagementClient . RoleAssignments . List ( parameters )
191
- . RoleAssignments
192
- . FilterRoleAssignmentsOnRoleId ( AuthorizationHelper . GetRoleDefinitionFullyQualifiedId ( currentSubscription , options . RoleDefinitionId ) )
190
+ var tempResult = AuthorizationManagementClient . RoleAssignments . List ( parameters ) ;
191
+ result . AddRange ( tempResult . RoleAssignments . FilterRoleAssignmentsOnRoleId ( AuthorizationHelper . GetRoleDefinitionFullyQualifiedId ( currentSubscription , options . RoleDefinitionId ) )
193
192
. ToPSRoleAssignments ( this , ActiveDirectoryClient , options . ExcludeAssignmentsForDeletedPrincipals ) ) ;
194
193
194
+ while ( ! string . IsNullOrWhiteSpace ( tempResult . NextLink ) )
195
+ {
196
+ tempResult = AuthorizationManagementClient . RoleAssignments . ListNext ( tempResult . NextLink ) ;
197
+ result . AddRange ( tempResult . RoleAssignments . FilterRoleAssignmentsOnRoleId ( AuthorizationHelper . GetRoleDefinitionFullyQualifiedId ( currentSubscription , options . RoleDefinitionId ) )
198
+ . ToPSRoleAssignments ( this , ActiveDirectoryClient , options . ExcludeAssignmentsForDeletedPrincipals ) ) ;
199
+ }
200
+
195
201
// Filter out by scope
196
202
if ( ! string . IsNullOrEmpty ( options . Scope ) )
197
203
{
@@ -203,17 +209,31 @@ public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions
203
209
// Filter by scope and above directly
204
210
parameters . AtScope = true ;
205
211
206
- result . AddRange ( AuthorizationManagementClient . RoleAssignments . ListForScope ( options . Scope , parameters )
207
- . RoleAssignments
208
- . FilterRoleAssignmentsOnRoleId ( AuthorizationHelper . GetRoleDefinitionFullyQualifiedId ( currentSubscription , options . RoleDefinitionId ) )
212
+ var tempResult = AuthorizationManagementClient . RoleAssignments . ListForScope ( options . Scope , parameters ) ;
213
+ result . AddRange ( tempResult . RoleAssignments . FilterRoleAssignmentsOnRoleId ( AuthorizationHelper . GetRoleDefinitionFullyQualifiedId ( currentSubscription , options . RoleDefinitionId ) )
209
214
. ToPSRoleAssignments ( this , ActiveDirectoryClient , options . ExcludeAssignmentsForDeletedPrincipals ) ) ;
215
+
216
+ while ( ! string . IsNullOrWhiteSpace ( tempResult . NextLink ) )
217
+ {
218
+ tempResult = AuthorizationManagementClient . RoleAssignments . ListForScopeNext ( tempResult . NextLink ) ;
219
+ result . AddRange ( tempResult . RoleAssignments . FilterRoleAssignmentsOnRoleId ( AuthorizationHelper . GetRoleDefinitionFullyQualifiedId ( currentSubscription , options . RoleDefinitionId ) )
220
+ . ToPSRoleAssignments ( this , ActiveDirectoryClient , options . ExcludeAssignmentsForDeletedPrincipals ) ) ;
221
+ }
210
222
}
211
223
else
212
224
{
213
- result . AddRange ( AuthorizationManagementClient . RoleAssignments . List ( parameters )
214
- . RoleAssignments
215
- . FilterRoleAssignmentsOnRoleId ( AuthorizationHelper . GetRoleDefinitionFullyQualifiedId ( currentSubscription , options . RoleDefinitionId ) )
216
- . ToPSRoleAssignments ( this , ActiveDirectoryClient , options . ExcludeAssignmentsForDeletedPrincipals ) ) ;
225
+ var tempResult = AuthorizationManagementClient . RoleAssignments . List ( parameters ) ;
226
+ result . AddRange ( tempResult . RoleAssignments
227
+ . FilterRoleAssignmentsOnRoleId ( AuthorizationHelper . GetRoleDefinitionFullyQualifiedId ( currentSubscription , options . RoleDefinitionId ) )
228
+ . ToPSRoleAssignments ( this , ActiveDirectoryClient , options . ExcludeAssignmentsForDeletedPrincipals ) ) ;
229
+
230
+ while ( ! string . IsNullOrWhiteSpace ( tempResult . NextLink ) )
231
+ {
232
+ tempResult = AuthorizationManagementClient . RoleAssignments . ListNext ( tempResult . NextLink ) ;
233
+ result . AddRange ( tempResult . RoleAssignments
234
+ . FilterRoleAssignmentsOnRoleId ( AuthorizationHelper . GetRoleDefinitionFullyQualifiedId ( currentSubscription , options . RoleDefinitionId ) )
235
+ . ToPSRoleAssignments ( this , ActiveDirectoryClient , options . ExcludeAssignmentsForDeletedPrincipals ) ) ;
236
+ }
217
237
}
218
238
219
239
if ( ! string . IsNullOrEmpty ( options . RoleDefinitionName ) )
@@ -252,12 +272,14 @@ public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions
252
272
/// Deletes a role assignments based on the used options.
253
273
/// </summary>
254
274
/// <param name="options">The role assignment filtering options</param>
275
+ /// <param name="subscriptionId">Current subscription id</param>
255
276
/// <returns>The deleted role assignments</returns>
256
277
public IEnumerable < PSRoleAssignment > RemoveRoleAssignment ( FilterRoleAssignmentsOptions options , string subscriptionId )
257
278
{
258
279
// Match role assignments at exact scope. Ideally, atmost 1 roleAssignment should match the criteria
259
280
// but an edge case can have multiple role assignments to the same role or multiple role assignments to different roles, with same name.
260
- IEnumerable < PSRoleAssignment > roleAssignments = FilterRoleAssignments ( options , subscriptionId )
281
+ // The FilterRoleAssignments takes care of paging internally
282
+ IEnumerable < PSRoleAssignment > roleAssignments = FilterRoleAssignments ( options , currentSubscription : subscriptionId )
261
283
. Where ( ra => ra . Scope == options . Scope . TrimEnd ( '/' ) ) ;
262
284
263
285
if ( roleAssignments == null || ! roleAssignments . Any ( ) )
@@ -307,7 +329,8 @@ public PSRoleDefinition GetRoleRoleDefinition(string name)
307
329
/// <summary>
308
330
/// Deletes a role definition based on the id.
309
331
/// </summary>
310
- /// <param name="id">The role definition id.</param>
332
+ /// <param name="roleDefinitionId">The role definition id to delete</param>
333
+ /// <param name="subscriptionId">Current subscription id</param>
311
334
/// <returns>The deleted role definition.</returns>
312
335
public PSRoleDefinition RemoveRoleDefinition ( Guid roleDefinitionId , string subscriptionId )
313
336
{
0 commit comments