Skip to content

Commit f8ebd0d

Browse files
authored
Fixed query issue when objectId in assignment is empty for Get-DenyAssignment (#20813)
1 parent 9cca982 commit f8ebd0d

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/Resources/Resources/ActiveDirectory/Models/ActiveDirectoryClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public IEnumerable<PSADUser> FilterUsers(ADObjectFilterOptions options, int firs
212212
/// </summary>
213213
public PSADObject GetObjectByObjectId(string objectId)
214214
{
215-
return GraphClient.DirectoryObjects.GetDirectoryObject(objectId)?.ToPSADObject();
215+
return string.IsNullOrEmpty(objectId) ? null : GraphClient.DirectoryObjects.GetDirectoryObject(objectId)?.ToPSADObject();
216216
}
217217

218218
/// <summary>

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+
* Fixed query issue when objectId in assignment is empty for `Get-DenyAssignment`
2223
* Fixed an issue where running deployment cmdlets with `-WhatIf` throws exception when formatting results with nested array changes
2324

2425
## Version 6.5.1

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public static IEnumerable<PSRoleAssignment> ToPSRoleAssignments(this IEnumerable
182182
List<PSADObject> adObjects = null;
183183
try
184184
{
185-
adObjects = objectIds.Count > 1 ? activeDirectoryClient.GetObjectsByObjectIds(objectIds) : new List<PSADObject>() { activeDirectoryClient.GetObjectByObjectId(objectIds.FirstOrDefault()) };
185+
adObjects = GetAdObjectsByObjectIds(objectIds, activeDirectoryClient);
186186
}
187187
catch (Common.MSGraph.Version1_0.DirectoryObjects.Models.OdataErrorException)
188188
{
@@ -222,6 +222,21 @@ public static IEnumerable<PSRoleAssignment> ToPSRoleAssignments(this IEnumerable
222222
return psAssignments;
223223
}
224224

225+
private static List<PSADObject> GetAdObjectsByObjectIds(List<string> objectIds, ActiveDirectoryClient activeDirectoryClient)
226+
{
227+
if (null == objectIds || 0 == objectIds.Count())
228+
{
229+
return new List<PSADObject>();
230+
}
231+
else if (1 == objectIds.Count())
232+
{
233+
return new List<PSADObject>() { activeDirectoryClient.GetObjectByObjectId(objectIds.FirstOrDefault()) };
234+
}else
235+
{
236+
return activeDirectoryClient.GetObjectsByObjectIds(objectIds);
237+
}
238+
}
239+
225240
private static IEnumerable<PSPrincipal> ToPSPrincipals(this IEnumerable<Principal> principals, IEnumerable<PSADObject> adObjects)
226241
{
227242
var psPrincipals = new List<PSPrincipal>();
@@ -265,7 +280,7 @@ public static PSDenyAssignment ToPSDenyAssignment(this DenyAssignment assignment
265280

266281
try
267282
{
268-
adObjects = objectIds.Count() <= 1 ? new List<PSADObject>() { activeDirectoryClient.GetObjectByObjectId(objectIds.FirstOrDefault()) } : activeDirectoryClient.GetObjectsByObjectIds(objectIds);
283+
adObjects = GetAdObjectsByObjectIds(objectIds, activeDirectoryClient);
269284
}
270285
catch (Common.MSGraph.Version1_0.DirectoryObjects.Models.OdataErrorException)
271286
{
@@ -306,7 +321,7 @@ public static IEnumerable<PSDenyAssignment> ToPSDenyAssignments(this IEnumerable
306321
List<PSADObject> adObjects = null;
307322
try
308323
{
309-
adObjects = objectIds.Count() <= 1 ? new List<PSADObject>() { activeDirectoryClient.GetObjectByObjectId(objectIds.FirstOrDefault()) } : activeDirectoryClient.GetObjectsByObjectIds(objectIds);
324+
adObjects = GetAdObjectsByObjectIds(objectIds, activeDirectoryClient);
310325
}
311326
catch (Common.MSGraph.Version1_0.DirectoryObjects.Models.OdataErrorException)
312327
{

0 commit comments

Comments
 (0)