Forum Discussion
- Thomas BermanIron Contributor
Hi there,
To grab the template of a modern team site, you can use PnP PowerShell (or C#) Get-PnPProvisioningTemplate.
How to create the modern team site programmatically will depend on whether you want it to be group connected or not. For a non group connected team site, simply call your normal CSOM or PnP method for creating a site and pass in Template STS#3.
For a group connected team site, you need to create an Office 365 group and pass in a "mailNickname" parameter which will determine the name of the team site.
You can do this in a number of ways. With REST via a POST request to the Graph endpoint: https://graph.microsoft.com/v1.0/groups
The following would create an Office 365 group and an associated "modern" team site with a URL of https://[tenant].sharepoint.com/sites/mymodernteamsite
POST https://graph.microsoft.com/v1.0/groups
Content-type: application/json
Content-length: 200
{
"description": "description",
"displayName": "My modern team site",
"groupTypes": [
"Unified"
],
"mailEnabled": true,
"mailNickname": "mymodernteamsite",
"securityEnabled": false
}You can also achieve this via PowerShell as explained in the following article
Note that you can't create group connected team sites using PowerShell with App-Only permissions yet, however, you should be able to call the Graph endpoint.
- null nullIron Contributor
Is there a way to use CSOM or PnP method for creating a site and pass in Template STS#3 using C#?
As i want to create the site collection programmatically using templates based on Modern Team Sites without group creation.
Thanks
- Thomas BermanIron Contributor
Using the PnP Core library, you can use the tenant extension method, "CreateSiteCollection", which accepts a SiteEntity object as a parameter. That SiteEntity object defines (among other things) the template (STS#3 in this case).
I would use the PnP method. Inside that method you'll see the CSOM method it's wrapped around (tenant.CreateSite()) which takes a SiteCreationProperties object which defines the template. You could also use that method directly if you want pure CSOM.