powershell icon indicating copy to clipboard operation
powershell copied to clipboard

[BUG] New-PnPTeamsTeam - 'PnP.PowerShell.Commands.Model.Graph.GraphException' was thrown.

Open Nibushi opened this issue 5 years ago • 2 comments

Reporting an Issue or Missing Feature

When trying to use the command New-PnPTeamsTeam I receive the following error: New-PnPTeamsTeam -DisplayName "Test PnP Team" -MailNickName "TestPnPTeam"

New-PnPTeamsTeam: Exception of type 'PnP.PowerShell.Commands.Model.Graph.GraphException' was thrown.

I have tried using Connect-PnPOnline with the scopes parameter (Connect-PnPOnline -Scopes "Group.ReadWrite.All") and with clientId and ClientSecret (Connect-PnPOnline -ClientId $clientId -ClientSecret $clientSecret -AADDomain $tenant).

Expected behavior

New Team called Test PnP Team would be created in Teams with an email address of TestPnPTeam

Actual behavior

image

Steps to reproduce behavior

  1. Connect-PnPOnline -Scopes "Group.ReadWrite.All"
  2. New-PnPTeamsTeam -DisplayName "Test PnP Team" -MailNickName "TestPnPTeam"

What is the version of the Cmdlet module you are running?

PnP.PowerShell - 0.3.33

Which operating system/environment are you running PnP PowerShell on?

  • [x ] Windows
  • [ ] Linux
  • [ ] MacOS
  • [ ] Azure Cloud Shell
  • [ ] Azure Functions
  • [ ] Other : please specify

Nibushi avatar Jan 12 '21 20:01 Nibushi

This occurs for me using 0.3.33 too - here are some further details:

It seems the Azure AD group is created but then the "Teamify" process fails so it does not create the Team

image

Here is the exception message

image

Message          : Exception of type 'PnP.PowerShell.Commands.Model.Graph.GraphException' was thrown.
Stacktrace       :    at PnP.PowerShell.Commands.Utilities.REST.GraphHelper.SendMessageAsync(HttpClient httpClient, HttpRequestMessage message) in
                   D:\a\powershell\powershell\src\Commands\Utilities\REST\GraphHelper.cs:line 316
                      at PnP.PowerShell.Commands.Utilities.REST.GraphHelper.PutAsync[T](HttpClient httpClient, String url, T content, String accessToken) in
                   D:\a\powershell\powershell\src\Commands\Utilities\REST\GraphHelper.cs:line 281
                      at PnP.PowerShell.Commands.Utilities.TeamsUtility.NewTeamAsync(String accessToken, HttpClient httpClient, String groupId, String displayName, String description, String
                   classification, String mailNickname, String owner, GroupVisibility visibility, TeamCreationInformation teamCI) in
                   D:\a\powershell\powershell\src\Commands\Utilities\TeamsUtility.cs:line 140
                      at PnP.PowerShell.Commands.Graph.NewTeamsTeam.ExecuteCmdlet() in D:\a\powershell\powershell\src\Commands\Teams\NewTeamsTeam.cs:line 122
                      at PnP.PowerShell.Commands.Base.BasePSCmdlet.ProcessRecord() in D:\a\powershell\powershell\src\Commands\Base\BasePSCmdlet.cs:line 54
                      at System.Management.Automation.Cmdlet.DoProcessRecord()
                      at System.Management.Automation.CommandProcessor.ProcessRecord()
ScriptLineNumber : 1

LeonArmston avatar Jan 13 '21 11:01 LeonArmston

My initial investigation shows that it seems to take suddenly longer for the underlying Microsoft 365 Group to be created fully. While the API immediately returns the group (which we then 'teamify'), doing the teamify task immediately after creating the group seems to throw this exception. We added a retry loop now to make sure we can teamify a group. We'll try 10 times and if then not succeeded we give up. For each iteration we wait 5 seconds to give the Graph the time to 'catch up'. This fix will be available in 0.3.35-nightly.

erwinvanhunen avatar Jan 13 '21 18:01 erwinvanhunen