From 2c35b57d48b8f2b1afb874ed6d758c437cc7be2c Mon Sep 17 00:00:00 2001 From: Giacomo Pozzoni Date: Wed, 3 Jul 2024 23:22:39 +0200 Subject: [PATCH] Fix null exception in Update-PnPTeamsUser Fix null dereference exception in Update-PnPTeamsUser happening right after a user is removed from a Team but still in the connected M365 group, for the few seconds that the 2 are out of sync. --- src/Commands/Teams/UpdateTeamsUser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/Teams/UpdateTeamsUser.cs b/src/Commands/Teams/UpdateTeamsUser.cs index fc2838b61..b610698e9 100644 --- a/src/Commands/Teams/UpdateTeamsUser.cs +++ b/src/Commands/Teams/UpdateTeamsUser.cs @@ -40,7 +40,7 @@ protected override void ExecuteCmdlet() { // No easy way to get member Id for teams endpoint, need to rely on display name filter to fetch memberId of the specified user and then update var teamUserWithDisplayName = TeamsUtility.GetTeamUsersWithDisplayName(this, Connection, AccessToken, groupId, specifiedUser.DisplayName); - var userToUpdate = teamUserWithDisplayName.Find(u => u.UserId == specifiedUser.Id); + var userToUpdate = teamUserWithDisplayName.Find(u => u.UserId == specifiedUser.Id) ?? throw new PSArgumentException($"User found in the M365 group but not in the team "); // Pass the member id of the user whose role we are changing WriteObject(TeamsUtility.UpdateTeamUserRole(this, Connection, AccessToken, groupId, userToUpdate.Id, Role));