'Create team with powershell

Everyone. I am going to create team with powershell. I have created .ps1 file and write the content as following.

Connect-MicrosoftTeams
New-Team -DisplayName "Tech Reads"

But I had got an error like this.

New-Team : Error occurred while executing
Code: Request_BadRequest
Message: Unsupported token. Unable to initialize the authorization context.
InnerError:
  RequestId: a2abece6-8676-4288-b7f2-fa9103423cb7
  DateTimeStamp: 2021-08-12T01:02:40
HttpStatusCode: Request_BadRequest
At D:\git\create-team-powershell\create-team.ps1:2 char:1
+ New-Team -DisplayName "Tech Reads"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-Team], ApiException
    + FullyQualifiedErrorId : Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException,Microsoft.TeamsCmdle
   ts.PowerShell.Custom.NewTeam

I can 't understand why this happens and hope your kind help. Thank you.



Solution 1:[1]

You need to at least also include Connect-AzureAD and Connect-AzAccount at the beginning of the script, and of course provide proper credentials with the right access rights.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bender the Greatest