SharePoint Online: How to fix error for creating new teams site

H Risbud 251 Reputation points
2023-01-30T16:42:51.3833333+00:00

Hello Everyone, While creating new Teams site using PnP Powershell, I'm getting error. How to overcome this error?

"New-PnPTeamsTeam : Caller does not have the required permissions for accessing this API. AllowedPermissions:'TeamMember.ReadWriteNonOwnerRole.All,TeamMember.ReadWrite.All'"

Connect-PnPOnline -Interactive
New-PnPTeamsTeam -DisplayName $SiteTitle -Description $SiteDescription -MailNickName $SiteName -Owners $TeamSiteOwner -Visibility Private

Thanks in advance

Microsoft 365 and Office | SharePoint | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
Microsoft Teams | Microsoft Teams for business | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. ERIC MILA 5 Reputation points
    2023-01-30T21:58:35.62+00:00

    Hi H Risbud

    Vérify you use these modules :

    Import-Module MSOnline
    Import-Module ExchangeOnlineManagement
    Import-Module MicrosoftTeams
    Import-Module -Name Microsoft.Online.SharePoint.PowerShell
    Import-Module PnP.PowerShell
    

    It's more easier :

    • create UnifiedGroup 365
    • put users inside
    • use New-Team -group ... to add Teams on this group

    If you want personalize Team's Sharepoint you can use :

    Connect-PnPOnline -Credential $credentials -Url $_site_sharepoint 
    Add-PnPFolder -Name "SCAN" -Folder ($_sharepoint_chemin + "/Documents partages/General") # by example for add folder
    

    I hope bring some help to you


  2. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-01-31T09:14:29.8866667+00:00

    Hi @H Risbud

    As the error message, you will need 'TeamMember.ReadWriteNonOwnerRole.All,TeamMember.ReadWrite.All' permission to call this api.

    First you need to register azure ad app only by following steps

    Granting access via Azure AD App-Only

    Then you need to grant TeamMember.ReadWrite.All permission to the app like following

    enter image description here

    Finally you can use following cmdlet to connect sharepoint

    $password = (ConvertTo-SecureString -AsPlainText 'myprivatekeypassword' -Force)
    Connect-PnPOnline -Url "contoso.sharepoint.com" -ClientId 6c5c98c7-e05a-4a0f-bcfa-0cfc65aa1f28 -CertificatePath 'c:\mycertificate.pfx' -CertificatePassword $password  -Tenant 'contoso.onmicrosoft.com'
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.