Automating SharePoint Online
Utilize Powershell to create and apply templates, customize and implement sites for your SharePoint tenants.
If you’re familiar with SharePoint Online (SPO) site and hub pages, you would be aware that applying templates to them can be fraught with difficulty and frustration. Natively, SharePoint (SP) seems to have provided fewer and fewer options for customizing templates, saving them and applying as time has gone on. The other issue is that, depending on your tenant and site configuration, you may not have access to any templating options.
Recently, we’ve been working with one of our clients to completely overhaul and rebuild their SharePoint based intranet. The rebuild has consisted of splitting their current solution, existing as a single landing site, into a suite of interconnected departmental landing hub pages and child team sites. Given the large number of sites requiring creation and the desire to maintain branding assets and display settings across these new hub and team sites; Lumity identified the need for a template management system to maintain visual continuity and a consistent UX across the board.
Microsoft maintains a PowerShell command library used to perform “complex provisioning and artifact management actions towards SharePoint” 1 called SharePoint Patterns and Practices (PnP). This library can be utilized to perform all kinds of actions such as creating and applying templates, programmatically altering the ‘change the look’ options, and much, much more. Here at Lumity, we’ve used PnP to fully automate the creation of SP templates and their application to existing teams and communications sites.
Our simple PnP solution, titled the ‘SharePoint Site Migrator’, includes two scripts; one to export a template to local template files and another to deploy those template files to an existing SP site. This solution will copy the entirety of a SharePoint Site, including all pages (and page structure, i.e. Web Parts, their locations on a page and config where possible), documents, lists, etc. It will even maintain the hub settings applied to a site, such as what it’s associated hub is - so make sure you alter this where needed. You can find the tool available here: Sharepoint Site Migrator
We recommend following the steps outlined in the documentation README.md included in the root project folder - noting some of the following caveats and SP idiosyncrasies:
- This solution was created with our client in mind, so we recommend altering the scripts where necessary for your own purposes.
- The invoke template script handles applying templates to teams and communications sites differently. This is due to two reasons, firstly, some display options (namingly footers) are not available on teams sites. The second is that we wanted to differentiate visually between the two site types.
- The export template script utilizes a JSON configuration file to dictate which handlers to run during SP side, when creating the template files, more info on the config file and it’s config options here: Link
- Some of the Handlers that run on SP that are called by the PnP package, dictated by the JSON configuration file within the project, fail depending on your design settings for a site (Known SP PnP bugs at the time of writing). This is why, for example, we manually handle the adding of asset files to the template in the export script.
We’ve been utilizing this project to automate the creation of sites for our client with great success. However you should generate some test sites to ensure that the template apply correctly, for your own purposes - should you decide to utilize our project.
Hopefully, in the future - Microsoft will provide some better, inbuilt SP tools to manage site templating within the browser. But for now, we have SP PnP and Lumity’s own Sharepoint Site Migrator.