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
1 change: 1 addition & 0 deletions src/Sql/Sql/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
## Upcoming Release
* Added UsePrivateLinkConnection to `New-AzSqlSyncGroup`, `Update-AzSqlSyncGroup`, `New-AzSqlSyncMember` and `Update-AzSqlSyncMember`
* Added SyncMemberAzureDatabaseResourceId to `New-AzSqlSyncMember` and `Update-AzSqlSyncMember`
* Add Guest user lookup support to Set SQL Server Azure Active Directory Admin cmdlet

## Version 2.6.1
* Enhance performance of:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ protected ServerAzureADAdministrator GetActiveDirectoryInformation(string displa
// Get a list of groups from Azure Active Directory
groupList = ActiveDirectoryClient.FilterGroups(filter).Where(gr => string.Equals(gr.DisplayName, displayName, StringComparison.OrdinalIgnoreCase));

if (groupList.Count() > 1)
if (groupList != null && groupList.Count() > 1)
{
// More than one group was found with that display name.
throw new ArgumentException(string.Format(Microsoft.Azure.Commands.Sql.Properties.Resources.ADGroupMoreThanOneFound, displayName));
}
else if (groupList.Count() == 1)
else if (groupList != null && groupList.Count() == 1)
{
// Only one group was found. Get the group display name and object id
group = groupList.First();
Expand All @@ -224,17 +224,12 @@ protected ServerAzureADAdministrator GetActiveDirectoryInformation(string displa

var applicationList = ActiveDirectoryClient.GetApplicationWithFilters(odataQueryFilter);

// No application was found
if (applicationList == null || applicationList.Count() == 0)
{
throw new ArgumentException(string.Format(Microsoft.Azure.Commands.Sql.Properties.Resources.ADObjectNotFound, displayName));
}
else if (applicationList.Count() > 1)
if (applicationList != null && applicationList.Count() > 1)
{
// More than one application was found.
throw new ArgumentException(string.Format(Microsoft.Azure.Commands.Sql.Properties.Resources.ADApplicationMoreThanOneFound, displayName));
}
else if (applicationList.Count() == 1)
else if (applicationList != null && applicationList.Count() == 1)
{
// Only one user was found. Get the user display name and object id
PSADApplication app = applicationList.First();
Expand Down Expand Up @@ -294,6 +289,20 @@ protected ServerAzureADAdministrator GetActiveDirectoryInformation(string displa
userList = ActiveDirectoryClient.FilterUsers(filter).Where(gr => string.Equals(gr.UserPrincipalName, displayName, StringComparison.OrdinalIgnoreCase));
}

// No user was found. Check if the display name is a guest user.
if (userList == null || userList.Count() == 0)
{
// Check if the display name is the UPN
filter = new ADObjectFilterOptions()
{
Id = (objectId != null && objectId != Guid.Empty) ? objectId.ToString() : null,
Mail = displayName,
Paging = true,
};

userList = ActiveDirectoryClient.FilterUsers(filter);
}

// No user was found
if (userList == null || userList.Count() == 0)
{
Expand Down