In this blog, you will see how to clone a team using Microsoft Teams Graph API in PowerShell.
Graph API can be used to automate Microsoft Teams lifecycle such as creating teams, channels, adding members etc.
Refer to this link to see the list of Graph API’s available for Microsoft Teams.
Prerequisites
Register an application in Azure and add Group.ReadWrite.All permissions. Refer to my previous article on “How to Access Microsoft Teams Graph API in Power Automate” to register an application in Azure Portal. Get the client ID and secret which will be used in script for authentication.
Clone Team Script
Step 1
Open Notepad and paste the following code. Save the file as CloneTeam.ps1.
Step 2
Open PowerShell window. Navigate to the folder path where the script file is saved.
- # Input Parameters
- $clientId = "c714f180-c8cc-4f70-b720-409c798274a9"
- $clientSecret = "fXzmWCUDmeXXqQ@D3b4xxd6GzrAY5[@="
- $tenantName = "c986.onmicrosoft.com"
- $resource = "https://graph.microsoft.com/"
- $URL = "https://graph.microsoft.com/v1.0/teams/daba3aa7-6622-4f75-8e27-a9587c6642dc/clone"
- $tokenBody = @{
- Grant_Type = "client_credentials"
- Scope = "https://graph.microsoft.com/.default"
- Client_Id = $clientId
- Client_Secret = $clientSecret
- }
- $body = @’
- {
- "displayName": "Cloned Team",
- "description": "Cloned Team using Graph API",
- "mailNickname": "clonedTeam",
- "partsToClone": "apps,tabs,settings,channels,members",
- "visibility": "public"
- }
- ‘@
- $tokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantName/oauth2/v2.0/token" -Method POST -Body $tokenBody
- Invoke-RestMethod -Headers @{Authorization = "Bearer $($tokenResponse.access_token)"} -Uri $URL -Method POST -Body $body -ContentType 'application/json'
Step 3
Execute the following script.
- .\CloneTeam.ps1
Step 4
Team cloned successfully.
Reference
https://docs.microsoft.com/en-us/graph/api/team-clone?view=graph-rest-1.0
Summary
Thus, in this blog, you saw how to clone a team using Microsoft Teams Graph API in PowerShell.

Cornel CraciunPosted Mar 16, 2021, 3:32 PM
Hello, I tried your solution and I get this error: Invoke-RestMethod : The remote server returned an error: (403) Forbidden.At C:\Users\myuser\source\repos\CreateTeamSite\CreateTeamSite\powershell solution script2.ps1:33 char:1+ Invoke-RestMethod -Headers @{Authorization = "Bearer $($tokenResponse ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc eption + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Bharat Bhushan KvPosted Apr 1, 2020, 3:03 PM
What are the values to be entered as per my Tenant in that PS script shared?