@@ -187,11 +187,16 @@ 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 ( options . RoleDefinitionId )
190
+ var tempResult = AuthorizationManagementClient . RoleAssignments . List ( parameters ) ;
191
+ result . AddRange ( tempResult . RoleAssignments . FilterRoleAssignmentsOnRoleId ( 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 ( options . RoleDefinitionId ) . ToPSRoleAssignments ( this , ActiveDirectoryClient , options . ExcludeAssignmentsForDeletedPrincipals ) ) ;
198
+ }
199
+
195
200
// Filter out by scope
196
201
if ( ! string . IsNullOrEmpty ( options . Scope ) )
197
202
{
@@ -203,15 +208,27 @@ public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions
203
208
// Filter by scope and above directly
204
209
parameters . AtScope = true ;
205
210
206
- result . AddRange ( AuthorizationManagementClient . RoleAssignments . ListForScope ( options . Scope , parameters )
207
- . RoleAssignments
208
- . FilterRoleAssignmentsOnRoleId ( options . RoleDefinitionId )
211
+ var tempResult = AuthorizationManagementClient . RoleAssignments . ListForScope ( options . Scope , parameters ) ;
212
+ result . AddRange ( tempResult . RoleAssignments . FilterRoleAssignmentsOnRoleId ( options . RoleDefinitionId )
209
213
. ToPSRoleAssignments ( this , ActiveDirectoryClient , options . ExcludeAssignmentsForDeletedPrincipals ) ) ;
214
+
215
+ while ( ! string . IsNullOrWhiteSpace ( tempResult . NextLink ) )
216
+ {
217
+ tempResult = AuthorizationManagementClient . RoleAssignments . ListForScopeNext ( tempResult . NextLink ) ;
218
+ result . AddRange ( tempResult . RoleAssignments . FilterRoleAssignmentsOnRoleId ( options . RoleDefinitionId )
219
+ . ToPSRoleAssignments ( this , ActiveDirectoryClient , options . ExcludeAssignmentsForDeletedPrincipals ) ) ;
220
+ }
210
221
}
211
222
else
212
223
{
213
- result . AddRange ( AuthorizationManagementClient . RoleAssignments . List ( parameters )
214
- . RoleAssignments . ToPSRoleAssignments ( this , ActiveDirectoryClient , options . ExcludeAssignmentsForDeletedPrincipals ) ) ;
224
+ var tempResult = AuthorizationManagementClient . RoleAssignments . List ( parameters ) ;
225
+ result . AddRange ( tempResult . RoleAssignments . ToPSRoleAssignments ( this , ActiveDirectoryClient , options . ExcludeAssignmentsForDeletedPrincipals ) ) ;
226
+
227
+ while ( ! string . IsNullOrWhiteSpace ( tempResult . NextLink ) )
228
+ {
229
+ tempResult = AuthorizationManagementClient . RoleAssignments . ListNext ( tempResult . NextLink ) ;
230
+ result . AddRange ( tempResult . RoleAssignments . ToPSRoleAssignments ( this , ActiveDirectoryClient , options . ExcludeAssignmentsForDeletedPrincipals ) ) ;
231
+ }
215
232
}
216
233
217
234
if ( ! string . IsNullOrEmpty ( options . RoleDefinitionName ) )
@@ -255,6 +272,7 @@ public IEnumerable<PSRoleAssignment> RemoveRoleAssignment(FilterRoleAssignmentsO
255
272
{
256
273
// Match role assignments at exact scope. Ideally, atmost 1 roleAssignment should match the criteria
257
274
// but an edge case can have multiple role assignments to the same role or multiple role assignments to different roles, with same name.
275
+ // The FilterRoleAssignments takes care of paging internally
258
276
IEnumerable < PSRoleAssignment > roleAssignments = FilterRoleAssignments ( options , currentSubscription : string . Empty )
259
277
. Where ( ra => ra . Scope == options . Scope . TrimEnd ( '/' ) ) ;
260
278
0 commit comments