Share and Enjoy !

Introduction – PnP PowerShell Provisioning

After my last blog post on provisioning modern SharePoint site collections, a fellow coworker suggested creating a walkthrough of PnP PowerShell provisioning for SharePoint Site Collections, so I wanted to share the quick steps to provision a modern Team site using PnP PowerShell. Additionally, how you can easily use site templates in PnP PowerShell to customize new sites.  In my example below, I was provisioning modern Team sites.  This is a quick summary of what I learned when looking at PnP PowerShell for provisioning modern sites in SharePoint Online.

Steps to Extract the Site Template

If you need to install the SharePoint Online PnP PowerShell module:

  • Run PowerShell as an Administrator, and run the following command: Install-Module SharePointPnPPowerShellOnline

  • Connect to the SharePoint Online Site that you want to copy and make a template of: Connect-PnPOnline -Url https://{your tenant SharePoint}
  • You should be prompted for credentials, and then enter your site collection administrator credentials.
  • Extract the site template to your local computer using the following command: Get-PnPProvisioningTemplate -Out “{folder location in drive}\TeamTemplate.xml” -ExcludeHandlers ApplicationLifecycleManagement,SiteSecurity -ExcludeContentTypesFromSyndication

You should see something like the following while the template file is being created:

Here is the template file that was created on my local machine:

Steps to Create a New SharePoint Team Site

Steps to Create a New SharePoint Team Site

  1. Create

    To create a new modern Team Site named ‘TeamSite2’, run this command: New-PnPSite -Title TeamSite2 -Type TeamSite -Alias TeamSite2

  2. Notice

    Notice that the site collection type was noted as ‘TeamSite’ to create the modern team site.

  3. Connect

    Then connect to the new site: Connect-PnPOnline -Url https://{your tenant SharePoint}

Steps to Apply the Template to a new Team Site

  • To apply the template created previously from the original ‘TeamSite’, run this command: Apply-PnPProvisioningTemplate -Path “{folder location in drive}\TeamTemplate.xml”
applying template screenshot

A few notes:  this example was just for a modern team site.  The team site was simple with no subsites.  In my test example, I manually customized the home page in the ‘TeamSite’ to add the highlighted content web part, which displays site pages, before extracting the template from this site collection.

Home Page for the Original ‘TeamSite’ Modern Team Site
Home Page for the Original ‘TeamSite’ Modern Team Site
New TeamSite2 Just After the Basic New Site Collection Was Created
New TeamSite2 Just After the Basic New Site Collection Was Created
TeamSite2 After the Template From ‘TeamSite’ Was Applied to This New Site

Notice above that the custom highlighted content, web part on the home page is now present in TeamSite2. It will display the current page content from the new TeamSite2 site.

Conclusion – PnP PowerShell Provisioning

Since the template is an XML file, it should be easy to customize it before applying it to new sites.  Using PnP PowerShell to extract and apply site templates can be a powerful way to provision large numbers of SharePoint sites in Microsoft 365, especially when you want the look and feel to be consistent across the sites.

Share and Enjoy !

Related Content: