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 = "vkenqqj35v-c8cc-4f70-b720-409c798274a9"
$clientSecret = "fXzmWCUDmeXXqQ@Frvoenjen6c6eg5b[@="
$tenantName = "windowsinsiderteam.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": "Test App",
"description": "Cloned Team using Graph API",
"mailNickname": "DuplicateTeam",
"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