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.
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.