Provisioning Sites From Site Designs Using PnP PowerShell - Pros And Cons Of Using PnP PowerShell Scripts

Introduction

 
Microsoft has introduced many modern ways to customize or write SharePoint solutions instead of a feature-based framework.
 
There are various approaches to plan and automate the process for site creation and management of SharePoint online sites.
 
Site template creation is one of the best features provided by Microsoft in SharePoint sites to create new sites with a similar structure for better SharePoint development for on-premise.
 
In-Office 365 the newest capability to create SharePoint sites based on a template has been rolled out. Once new SharePoint sites are created, site designs and site scripts automatically apply the custom configuration. It is fully integrated into the SharePoint UI and offers an alternative to the PnP provisioning engine.
 
PnP is an open-source project maintained by Microsoft and the community has come up with new features called PnP provisioning templates to provision the sites in SharePoint Online. It's a very nice feature with vast capabilities but requires more effort, even if you want very few configurations.
 
Microsoft has introduced Site Design & Site Scripts along with PnP provisioning templates to support custom configurations with less effort than PnP provisioning templates. Currently, only SharePoint online supports Site Designs and Site Scripts.
 
In this article, we'll look at PnP provisioning PowerShell, Site Scripts, and how to use what is given by PnP PowerShell and what isn't supported with the best possible approach.
 
PnP Provisioning PowerShell is an excellent way to automate the creation of SharePoint assets using PowerShell, using an XML Or PnP template file. Similarly, Site Scripts and Site Design-assist us to create a site using JSON templates and allow you to call any automation scripts or use a template for a custom implementation
 

Site designs

 
Site Design is a predefined set of actions that can be used in SharePoint online to create new sites using the modern UI. It will help you have consistency within the same tenant across multiple site collections. For example, you can create new lists/libraries, site/list columns, types of content, set themes, set the site logo, etc. we can apply Site Design to existing sites using PnP PowerShell scripts. Site Designs are basically a package of scripts that runs in the background when you select a design to create a new site.
 
Understanding Site Scripts
 
Create a SharePoint Modern Team site to be used as a template and generate a provisioning template from PnP PowerShell it.
 
PnP is a community-sponsored, open-source project, not Microsoft. Now Microsoft has brought its own gadget to the soccer field on the provisioning site. It supports flow triggering but it includes far fewer functions than PnP in terms of provisioning.
 
The schema of the site script is not difficult to comprehend since it is based on a JSON structure that works with a list of actions.
 
Each action is specified by a verb value that must be correctly written since it is treated as case-sensitive values.
 
Below is a list of the actions supported,
  • applyTheme: Applies a custom theme
  • setSiteExternalSharingCapability: Manages guest access
  • createSPList: Creates a new list
  • addNavLink: Adds a navigation link
  • triggerFlow: Triggers a Microsoft flow
  • setSiteLogo: Sets a logo to a communication site (Not supported in team sites)
  • joinHubSite: Joins a hub site
  • With more to come next action support road map :
  • Create modern pages; set as home page
  • Add declarative formatting to a column
  • Join site to Hub
  • Enable external access
  • Set site classification
Use the following PnP PowerShell cmdlet to ensure that the generated template does not have any elements that are not needed for the provisioning.
 
Open SharePoint Online PowerShell command prompt.
 
Install-Module -Name SharePointPnPPowerShellOnline -RequiredVersion 3.2.1810.0 Connect-PnPOnline -Url https://pointerone.sharepoint.com/sites/PracticeDemo
 
Get-PnPProvisioningTemplate -Out "E:\Path\to\Provisioningtemplate.xml" -Handlers "Lists" -
 
ExcludeHandlers "SiteSecurity,TermGroups,Fields,ContentTypes,Navigation" -Force
 
 
The output of the above cmdlet is ProvisioningTemplate.xml file which could be applied to new sites for setting up the same SharePoint elements.
 
Note
Latest PnP PowerShell package for all version Reference URL
 
 

Site designs + PnP + Flow approach

 
Site design selections appears in site provisioning UX(per base template).executing site design we use actions like,
  • Create List
  • Apply Theme
  • Add to nav
  • Trigger flow
  • Join a Hub site
We stored the selected site design in the property bag of the site. We start the site provisioning using Microsoft flow.
 
Microsoft flow can trigger some remote code andyou will need to execute other newly created site configurations. This allows you to chain a bunch of other things into what you have been able to do with site design – for instance, actions in my list of things that are not possible in site designs alone.
 
Naturally, the logical thing to do here is to apply a PnP template to the site, as we would have done before site designs
 
The pattern is,
  • Site gets created from site design
  • Site design steps are applied
  • Custom Microsoft flow is called – this puts an item onto an Azure queue with details (e.g. URL) of the new site
  • The Azure queue uses a queue trigger to start an Azure Function (or web job if you prefer)
  • The function applies a PnP template to the site 
Flow structure in below,
 
 

Pros & Cons

 
SharePoint Patterns and Practices (PnP) contains a PowerShell command library (PnP PowerShell), which enables you to perform complex provisioning and artifact management actions towards SharePoint.
 
Pros
  • PnP PowerShell adds to that and allows admins (both Tenant and Site Collection admins) to manage and implement automation workloads from scripts
  • Easy to install SharePoint PnP PowerShell cmdlets ex: Install-Module SharePointPnPPowerShellOnline
  • No hosting requirements besides a system where PowerShell (>5.0) is installed
  • One line cmdlets for most complex SharePoint implementation scenarios
  • Easy to convert a classic SharePoint page to modern using PnP
  • PnP PowerShell open source and easy to customize
  • Provides a non-custom master responsive strategy for classic sites
  • Microsoft preferred method, cloud-ready and no Visual Studio Or coding
Cons
  • Parallel tasking for more data intensive operations is challenging
  • Not much options for extensibility besides the ones provided
  • Not all Site operations such as taxonomy field updates (unless do XML schema update) are supported yet
  • No toolchain to build from: Simple JS/ CSS / PnP scripts
Microsoft has increased limit to 300 actions or 1,00,000 characters for the scripts applied asynchronously either through UI or commands in using PnP PowerShell, and there is likewise a limit of 100 site scripts and 100 site designs per tenant.