Close this search box.
Azure Active Directory Microsoft 365

Clone a Team Using Microsoft Graph API In PowerShell

Clone a Team Using Microsoft 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.


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 = "vkenqqj35v-c8cc-4f70-b720-409c798274a9"  
$clientSecret = "fXzmWCUDmeXXqQ@Frvoenjen6c6eg5b[@="  
$tenantName = ""  
$resource = ""  
$URL = ""  
$tokenBody = @{  
    Grant_Type    = "client_credentials"  
    Scope         = ""  
    Client_Id     = $clientId  
    Client_Secret = $clientSecret  
$body = @’  
     "displayName": "Test App",  
     "description": "Cloned Team using Graph API",  
     "mailNickname": "DuplicateTeam",  
     "partsToClone": "apps,tabs,settings,channels,members",  
     "visibility": "public"  
$tokenResponse = Invoke-RestMethod -Uri "$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


Step 4

Team cloned successfully.


About Author

Rezwanur Rahman

Rezwanur Rahman is the Microsoft Graph MVP, located in Innsbruck, Austria. He is the ex-Microsoft employee at Microsoft Bangladesh, and Microsoft Technical Support Lead for Microsoft 365 Global Support. He is a software engineer graduate and currently contributing technical knowledge on Microsoft Copilot and ChatGPT.