I am currently writing a Powershell script to create teams in Microsoft Teams.
Is there a way to use a template when creating a team in Powershell?
Thanks in advance.
CodePudding user response:
Yes, it is possible, but not with the MicrosoftTeamsPowerShell
module's New-Team
. As per the docs, the -Template
parameter is for Education customers:
If you have an EDU license, you can use this parameter to specify which template you'd like to use for creating your group. Do not use this parameter when converting an existing group. Valid values are: "EDU_Class" or "EDU_PLC"
Instead, you can do this using Microsoft Graph, in particular the Create Team
operation. One of the examples listed in the docs describes how to use the AdditionalProperties to specify a template, and once you know it's possible in Graph in concept, it's simply a case of finding the matching operation in the Microsoft Graph PowerShell module, in this case New-MgTeam
(more info here).
For some final code, you can use the following:
Connect-MgGraph -Scopes "Team.Create"
$additionalProperties = @{
"[email protected]" = "https://graph.microsoft.com/v1.0/teamsTemplates('com.microsoft.teams.template.ManageAProject')"
}
New-MgTeam -DisplayName "SOTest" -AdditionalProperties $additionalProperties
This example using the Project Team template - here is a list of the out of box templates. For your custom templates, you can create them in the admin centre or via PowerShell, and you can read more about them here. To actually use a custom template, you use it's Guid in the form of:
$additionalProperties = @{
"[email protected]" = "https://graph.microsoft.com/v1.0/teamsTemplates('[your guid here]')"
}
Just a final note to be aware of - the PowerShell command executes quite quickly, and it creates the initial team pretty fast too, but it takes a few minutes to apply the template thereafter (e.g. creating the channels etc.) - give it 5 - 10 minutes and it should be fine.