Share via


Provisioning sites from Site designs using PnP PowerShell - Pros & Cons of using PnP PowerShell Scripts

Introduction

Microsoft Has Introduced Many Modern Ways To Customize Or Write SharePoint Solutions Instead Of A Featured Based Framework.

There Are Various Approaches To Plan And Automate The Process For Site Creation And Management Of SharePoint Online Sites.

**Site Templates **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_43_PnP_43_Flow_approach

Site design selections appears in site provisioning UX(per base template).executing site design we action like:

  • Create List
  • Apply Theme
  • Add to nav
  • Trigger flow
  • Join a Hub site

 

we stored the selected site design in property bag of the site. We start the site provisioning using Microsoft flow.

Microsoft Flow can trigger some remote code you 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
  • 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 in .