diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dbee957b..61f9e3e1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed `New-PnPTeamsTeam` cmdlet, it will now throw error if it fails to teamify a Microsoft 365 group. [#3310](https://github.com/pnp/powershell/pull/3310) - Fixed `Connect-PnPOnline` cmdlet throwing host not reachable errors. [#3337](https://github.com/pnp/powershell/pull/3337) - Fixed `Set-PnPTerm` cmdlet throwing object reference error when only the term Id is specified. [#3341](https://github.com/pnp/powershell/pull/3341) +- Fixed `New-PnPTeamsTeam` cmdlet throwing an error when specifying members [#3351](https://github.com/pnp/powershell/pull/3351) +- Fixed `New-PnPTeamsTeam` cmdlet not working well with a managed identity [#3351](https://github.com/pnp/powershell/pull/3351) ### Changed @@ -47,6 +49,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Contributors +- Carl Joakim Damsleth [damsleth] - Rodel Pacurib [ryder-cayden] - [CatSchneider] - [msjennywu] diff --git a/src/Commands/Utilities/TeamsUtility.cs b/src/Commands/Utilities/TeamsUtility.cs index e3b0128eb..6ad798e80 100644 --- a/src/Commands/Utilities/TeamsUtility.cs +++ b/src/Commands/Utilities/TeamsUtility.cs @@ -195,33 +195,6 @@ public static async Task NewTeamAsync(string accessToken, PnPConnection co } if (group != null) { - // Construct a list of all owners and members to add - var teamOwnersAndMembers = new List(); - if (owners != null && owners.Length > 0) - { - foreach (var owner in owners) - { - teamOwnersAndMembers.Add(new TeamChannelMember { Roles = new List { "owner" }, UserIdentifier = $"https://{connection.GraphEndPoint}/v1.0/users('{owner}')" }); - } - } - - if (members != null && members.Length > 0) - { - foreach (var member in members) - { - teamOwnersAndMembers.Add(new TeamChannelMember { Roles = new List(), UserIdentifier = $"https://{connection.GraphEndPoint}/v1.0/users('{member}')" }); - } - } - - if (teamOwnersAndMembers.Count > 0) - { - var ownersAndMembers = BatchUtility.Chunk(teamOwnersAndMembers, 200); - foreach (var chunk in ownersAndMembers) - { - await GraphHelper.PostAsync(connection, $"v1.0/teams/{group.Id}/members/add", new { values = chunk.ToList() }, accessToken); - } - } - Team team = teamCI.ToTeam(group.Visibility.Value); var retry = true; var iteration = 0; @@ -251,7 +224,34 @@ public static async Task NewTeamAsync(string accessToken, PnPConnection co { retry = false; } - } + } + + // Construct a list of all owners and members to add + var teamOwnersAndMembers = new List(); + if (owners != null && owners.Length > 0) + { + foreach (var owner in owners) + { + teamOwnersAndMembers.Add(new TeamChannelMember { Roles = new List { "owner" }, UserIdentifier = $"https://{connection.GraphEndPoint}/v1.0/users('{owner}')" }); + } + } + + if (members != null && members.Length > 0) + { + foreach (var member in members) + { + teamOwnersAndMembers.Add(new TeamChannelMember { Roles = new List(), UserIdentifier = $"https://{connection.GraphEndPoint}/v1.0/users('{member}')" }); + } + } + + if (teamOwnersAndMembers.Count > 0) + { + var ownersAndMembers = BatchUtility.Chunk(teamOwnersAndMembers, 200); + foreach (var chunk in ownersAndMembers) + { + await GraphHelper.PostAsync(connection, $"v1.0/teams/{group.Id}/members/add", new { values = chunk.ToList() }, accessToken); + } + } } return returnTeam; } @@ -293,7 +293,7 @@ private static async Task CreateGroupAsync(string accessToken, PnPConnect } // Check if by now we've identified a user Id to become the owner - if (!string.IsNullOrEmpty(ownerId)) + if (string.IsNullOrEmpty(ownerId)) { var contextSettings = connection.Context.GetContextSettings();