Site Creation Automation

There is quite an appetite with our clients on being able to provision template sites at a click of a button (or more precisely, a submission for a list item). There are a whole range of benefits for business units to be able to use a list to trigger the creation of a templated site such as:

  • Ensuring that their sites all have the same set of document libraries and folders
  • The initial permission are setup ready for further refining
  • Having a familiar homepage that can be customized to the site’s specific content
  • Adding SharePoint Framework solutions to the site

In this blog we are going to cover high level architecture of the site automation Power Automate flow, the technologies we used and call out any technical challenges we had along the way.

What did we want to achieve?

For our specific use case we wanted a group of power users to be able to simply fill out a list form to provide information such as the site title, site URL, which template they want to apply (which document libraries/permissions/etc. to create) and who will be the site owner. Once submitted, a Power Automate flow will trigger to create the site according to the information provided, simple as that!

To be more specific, we wanted to:

Use the site templates (also known as site designs) to:

  • Apply regional settings for Australia and set the date/time to a local time zone
  • Create document libraries with predefined metadata
  • Update the left nav quick links
  • Install our custom SPFx apps (for this solution we created a custom list view command to help facilitate gathering feedback and approvals for selected documents)


Image: Summary of what we can achieve with site templates

Use the Rest API to:

  • Create a group-enabled site
  • Apply permissions to the site (i.e. set the owners and visitors)
  • Apply unique permissions to document libraries and folders
  • Copy a pre-configured SharePoint page and set it as the home page

Prerequisites

You’ll need:

  • PowerShell to create the site scripts and site templates
  • Access to the SharePoint Tenant Administration site

How did we do it?


Image: High-level process flow

We started with a simple list that captures details to kick off the process. We then created a Power Automate flow that is triggered when an item is created or modified in the list to create the site and notify the requester when it’s completed.

The Power Automate itself heavily leverages the SharePoint Rest API and Site templates to be able to apply all the good stuff. In a high-level summarised list, these are the key flow action steps:

  1. Create a group enable site using the Rest API (read this blog on how to do it). Alternatively, you can create a non-group enabled site depending on your needs:

2. Apply the site templates using the rest API (here is the endpoint and relevant documentation)

3. Apply custom permissions to folders:

4. Use the Rest API to handle permissions and copy over the home page:

Technical Challenges

There were a few quirky behaviours that I discovered and wanted to call out in-case you run into them as well:

  1. Regional settings in a Site template can only be applied when the site is created so make sure to list the site template to apply

Image: HTTP Request to SharePoint – The highlighted text is where your site template ID would go

2. To get the ID of security groups, I added them to a throw away site, navigated to Site permissions > Advanced Site Permissions > Selected the site group they were added to > Select the Security Group you want > Copied the Account name value.

3. Site templates can take a while to apply so you will want to add a delay action to wait for it to be fully applied before further interacting with the site.

4. When Site pages are copied over from one site to another, they may be copied as wiki pages which cannot be edited, we will need to use the SharePoint Rest API to change the content type to a page.

Final notes

I believe Microsoft are rebranding Site Designs to Site templates, so those terms are interchangeable within the blog (please note site scripts are a component of site templates/designs but are their own thing!)

Hopefully the above gives you a bit more information and a guideline on how you can automate your own site creation. I do appreciate that is pretty high-level and links to a few resources but I think that’s the best way to learn!

As always, feel free to reach out to me at evan.tse@engagesq.com if you’d like a demo of the solution or want to know how we can help get it up and running in your tenant to your requirements.


Leave a Comment

Your email address will not be published. Required fields are marked *