Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public IEnumerable<PSADUser> FilterUsers(ADObjectFilterOptions options, int firs
/// </summary>
public PSADObject GetObjectByObjectId(string objectId)
{
return GraphClient.DirectoryObjects.GetDirectoryObject(objectId)?.ToPSADObject();
return string.IsNullOrEmpty(objectId) ? null : GraphClient.DirectoryObjects.GetDirectoryObject(objectId)?.ToPSADObject();
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Resources/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->

## Upcoming Release
* Fixed query issue when objectId in assignment is empty for `Get-DenyAssignment`
* Fixed an issue where running deployment cmdlets with `-WhatIf` throws exception when formatting results with nested array changes

## Version 6.5.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public static IEnumerable<PSRoleAssignment> ToPSRoleAssignments(this IEnumerable
List<PSADObject> adObjects = null;
try
{
adObjects = objectIds.Count > 1 ? activeDirectoryClient.GetObjectsByObjectIds(objectIds) : new List<PSADObject>() { activeDirectoryClient.GetObjectByObjectId(objectIds.FirstOrDefault()) };
adObjects = GetAdObjectsByObjectIds(objectIds, activeDirectoryClient);
}
catch (Common.MSGraph.Version1_0.DirectoryObjects.Models.OdataErrorException)
{
Expand Down Expand Up @@ -222,6 +222,21 @@ public static IEnumerable<PSRoleAssignment> ToPSRoleAssignments(this IEnumerable
return psAssignments;
}

private static List<PSADObject> GetAdObjectsByObjectIds(List<string> objectIds, ActiveDirectoryClient activeDirectoryClient)
{
if (null == objectIds || 0 == objectIds.Count())
{
return new List<PSADObject>();
}
else if (1 == objectIds.Count())
{
return new List<PSADObject>() { activeDirectoryClient.GetObjectByObjectId(objectIds.FirstOrDefault()) };
}else
{
return activeDirectoryClient.GetObjectsByObjectIds(objectIds);
}
}

private static IEnumerable<PSPrincipal> ToPSPrincipals(this IEnumerable<Principal> principals, IEnumerable<PSADObject> adObjects)
{
var psPrincipals = new List<PSPrincipal>();
Expand Down Expand Up @@ -265,7 +280,7 @@ public static PSDenyAssignment ToPSDenyAssignment(this DenyAssignment assignment

try
{
adObjects = objectIds.Count() <= 1 ? new List<PSADObject>() { activeDirectoryClient.GetObjectByObjectId(objectIds.FirstOrDefault()) } : activeDirectoryClient.GetObjectsByObjectIds(objectIds);
adObjects = GetAdObjectsByObjectIds(objectIds, activeDirectoryClient);
}
catch (Common.MSGraph.Version1_0.DirectoryObjects.Models.OdataErrorException)
{
Expand Down Expand Up @@ -306,7 +321,7 @@ public static IEnumerable<PSDenyAssignment> ToPSDenyAssignments(this IEnumerable
List<PSADObject> adObjects = null;
try
{
adObjects = objectIds.Count() <= 1 ? new List<PSADObject>() { activeDirectoryClient.GetObjectByObjectId(objectIds.FirstOrDefault()) } : activeDirectoryClient.GetObjectsByObjectIds(objectIds);
adObjects = GetAdObjectsByObjectIds(objectIds, activeDirectoryClient);
}
catch (Common.MSGraph.Version1_0.DirectoryObjects.Models.OdataErrorException)
{
Expand Down