shutterstock_462376603.jpg

Walkthrough of PnP PowerShell Provisioning for ‘Modern’ SharePoint Site Collections

Introduction

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 provision 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}.sharepoint.com/sites/TeamSite
  • 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 Team Site

  • To create a new modern Team Site named ‘TeamSite2’, run this command: New-PnPSite -Title TeamSite2 -Type TeamSite -Alias TeamSite2
  • Notice that the site collection type was noted as ‘TeamSite’ to create the modern team site.
  • Then connect to the new site: Connect-PnPOnline -Url https://{your tenant SharePoint}.sharepoint.com/sites/TeamSite2

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

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

Since the template is a 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 Office 365, especially when you want the look and feel to be consistent across the sites.

Kristi WebbWalkthrough of PnP PowerShell Provisioning for ‘Modern’ SharePoint Site Collections

Join the conversation

This site uses Akismet to reduce spam. Learn how your comment data is processed.