Skip to content

[BUG] New-PnPTeamsTeam sporadically returns "Not Found (404): No Team found with Group id" #4757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 6 tasks
zapftho opened this issue Feb 25, 2025 · 1 comment
Open
1 of 6 tasks
Labels
bug Something isn't working

Comments

@zapftho
Copy link

zapftho commented Feb 25, 2025

Reporting an Issue or Missing Feature

Since yesterday we are facing issues with our Teams provisioning which relies on PnP Powershell. In our scripts we are using New-PnPTeamsTeam cmdlet and most of the times it is working fine. However, in some cases the command returns an error "Not Found (404): No Team found with Group id ". This has been working fine for quite a while now and suddenly started to behave like mentioned.

UPDATE 03.03.2025: I can now confirm that even after the update to 2.12.0 we are seeing this issue. I was hoping the update did fix this issue as I didn't receive any additional errors since implementing it last week. However, today the issues re-appeared. So it defnitely seems to be an issue. It looks like the issues happens when providing the members and / or owners properties to set them during creation of a team if I am not completely wrong: https://github.com/pnp/powershell/blob/master/src/Commands/Utilities/TeamsUtility.cs#L257

Expected behavior

New-PnPTeamsTeam finishes without error and returns the created team.

Actual behavior

New-PnPTeamsTeam sporadically fails with error "Not Found (404): No Team found with Group id "

Error / Stacktrace (Group ID has been anonymized):
Exception of type 'PnP.PowerShell.Commands.Model.Graph.GraphException' was thrown. Data : System.Collections.ListDictionaryInternal Source : PnP.PowerShell HResult : -2146233088 StackTrace : at PnP.PowerShell.Commands.Utilities.REST.GraphHelper.SendMessage(Cmdlet cmdlet, PnPConnection connection, HttpRequestMessage message, String accessToken) in c:\build\src\Commands\Utilities\REST\GraphHelper.cs:line 366 at PnP.PowerShell.Commands.Utilities.REST.GraphHelper.PostInternal[T](Cmdlet cmdlet, PnPConnection connection, String url, String accessToken, HttpContent content, IDictionary2 additionalHeaders, Boolean propertyNameCaseInsensitive) in c:\build\src\Commands\Utilities\REST\GraphHelper.cs:line 293 at PnP.PowerShell.Commands.Utilities.REST.GraphHelper.Post[T](Cmdlet cmdlet, PnPConnection connection, String url, T content, String accessToken) in c:\build\src\Commands\Utilities\REST\GraphHelper.cs:line 282 at PnP.PowerShell.Commands.Utilities.TeamsUtility.NewTeam(Cmdlet cmdlet, String accessToken, PnPConnection connection, String groupId, String displayName, String description, String classification, String mailNickname, GroupVisibility visibility, TeamCreationInformation teamCI, String[] owners, String[] members, Guid[] sensitivityLabels, TeamsTemplateType templateType, Nullable1[] resourceBehaviorOptions) in c:\build\src\Commands\Utilities\TeamsUtility.cs:line 255 at PnP.PowerShell.Commands.Teams.NewTeamsTeam.ExecuteCmdlet() in c:\build\src\Commands\Teams\NewTeamsTeam.cs:line 150 at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPConnectedCmdlet.cs:line 53 CategoryInfo : WriteError: (:) [New-PnPTeamsTeam], GraphException FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Teams.NewTeamsTeam ErrorDetails : Not Found (404): No Team found with Group id: xxxx-xxxx-xxxx-xxxx-xxxx

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

2.12.0

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

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : please specify
@zapftho zapftho added the bug Something isn't working label Feb 25, 2025
@zapftho
Copy link
Author

zapftho commented Mar 6, 2025

As the issue was getting even worse during the last days I have implemented a workaround in my Teams Provisioning script which I would like to share with you. It does not solve the actual issue with New-PnPTeamsTeam but at least it helps that our Teams creation finishes without errors and all users are added as expected.

try{
    $team = New-PnPTeamsTeam -DisplayName $TeamDisplayName -Description $TeamDescription -MailNickName $SharePointSiteUrlAndSiteId.SiteID -Visibility $Visibility -Owners $TeamOwners -Members $TeamMembers -AllowAddRemoveApps $false -AllowChannelMentions $true -AllowCreateUpdateChannels $false -AllowCreateUpdateRemoveConnectors $false -AllowCreateUpdateRemoveTabs $false -AllowCustomMemes $true -AllowDeleteChannels $false -AllowGiphy $true -AllowGuestCreateUpdateChannels $false -AllowGuestDeleteChannels $false -AllowOwnerDeleteMessages $false -AllowStickersAndMemes $true -AllowTeamMentions $true -AllowUserDeleteMessages $false -AllowUserEditMessages $false -GiphyContentRating "Moderate" -ShowInTeamsSearchAndSuggestions $true -Connection $pnpAdminConnection -ErrorAction Stop
}catch{
    #Workaround: In case the Teams creation fails with a not found error, we will wait some seconds and try to get the Team by its MailNickName, see https://github.com/pnp/powershell/issues/4757
    if(($_.Exception.HttpResponse.StatusCode -eq "404") -or ($_.ErrorDetails.Message -like '*Not Found (404): No Team found with Group id*')) {
        Write-Warning "Failed to get Team after creation. Trying to get Team again in 5 seconds. Error: $($_.ErrorDetails.Message)"
        Start-Sleep -Seconds 5
        $team = Retry-Command -ScriptBlock {Get-PnPTeamsTeam -Identity $SharePointSiteUrlAndSiteId.SiteID -Connection $pnpAdminConnection}

        #Cleanup - Add Members & Owners again as this part has failed during Teams creation
        if($TeamOwners.Count -gt 0){
            Add-PnPTeamsUser -Team $team -Users $TeamOwners -Role Owner -Connection $pnpAdminConnection -ErrorAction Stop
        }
        if($TeamMembers.Count -gt 0){
            Add-PnPTeamsUser -Team $team -Users $TeamMembers -Role Member -Connection $pnpAdminConnection -ErrorAction Stop
        }
    }
    else{
        throw
    }  
}

Note: "Retry-Command" is some custom function we are using to handle retries in case of errors

It seems like there is some delay before Graph API recognizes the created team and without some retries the action to add the Team members & owners in New-PnPTeamsTeam fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant