What is the best approach to programatically create a modern (team) site in the SharePoint 2019?

We need to create the sites and do some small customization before running migration. Since a special logic, I would preffer using C# CSOM/Pnp.Core libs. I am not sure whether this particular step is better to develop in PowerShell (running on the server side) Is there any example for this using PowerShell or CSOM ?

I have actually read the Create Site Collection using CSOM for SharePoint 2019 On-Premise ,but I am not sure, whether it works also with the modern sites?

1 Answer 1


After a time I think, the Create Site Collection using CSOM for SharePoint 2019 On-Premise can answer my question.

There must be added the TenantAdmin ServerStub to ClientCallableProxyLibrary for web application in order sucesfully create sites via CSOM.

The script for the SP2019/SP2016 allowtenantapiv16.ps1 could be found at https://github.com/SharePoint/sp-admin-scripts/tree/master/Scripts/SharePoint.SiteColProvisioning.Configuration

I still don't know it is the best approach. Using the CSOM and Tenant object, the both tenant.CreateSite(), tenant.CreateSiteCollection() worked. The 2nd one seemed to be faster.

            using (var ctxTenant = authMananger.GetNetworkCredentialAuthenticatedContext(tenantUrl, user, pw, domain))
            var tenant = new Tenant(ctxTenant);

            //SiteCreationProperties props = new SiteCreationProperties()
            //    Title = wi.Title,
            //    //Url = wi.TargetUrl,
            //    Url = "http://myserver/sites/Test1",
            //    Lcid = 1033,
            //    Template = "STS#3",
            //    Owner = domainUser


            SiteEntity siteEntity = new SiteEntity()
                Title = wi.Title,
                Url = siteUrl,
                Description = wi.Description,
                Lcid = 1033,
                Template = "STS#3",
                SiteOwnerLogin = domainUser


There is still one small inconvenience - the created site shows on its home page in the right upper corner the "0#.w|< domainUser >" instead of the user name - mightbe because a missing parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.