Site Provisioning in SharePoint Online - Step-by-Step Guide
Author: Vishal Thakur
Introduction
Site Provisioning or Site Templating is a developer-friendly feature of SharePoint. Using Site Templating, SharePoint allows you to create a replica of a Site Collection and use it to create similar sites for departmental or other purposes. It is easy to create and apply, requiring a one-time operation. However, there are some prerequisites to using it:
- Knowledge of PowerShell Scripts.
- Knowledge of PnP Module.
- Must have SharePoint Online Administrator credentials.
Step 1: Open PowerShell in Administrator Mode
Start by opening PowerShell in Administrator mode.
Step 2: Install the PnP Module
Run the following command to install the PnP module:
Install-Module -Name "PnP.PowerShell"
Step 3: Connect to SharePoint Online
Run the following command to connect to your SharePoint Online site:
Connect-SPOService -Url https://rb500-admin.sharepoint.com
After running the command, you will be prompted to enter your SharePoint admin credentials.
Step 4: Generate Site Script
Run the following command to generate a site script from an existing site:
Get-SPOSiteScriptFromWeb -WebUrl "https://test.sharepoint.com/sites/mysite" -IncludeTheme -IncludeBranding -IncludeSiteExternalSharingCapability -IncludeRegionalSettings -IncludeLinksToExportedItems -IncludedLists ("SiteAssets", "SitePages", "Lists/Tools", "Lists/Tips", "Lists/Quick Links List", "Lists/Highlights", "Lists/Footer Links", "Lists/Alerts", "Lists/Company News", "Lists/Article News", "Lists/Dashboard")
Step 5: Create JSON File
Copy the output generated by the above command and create a new JSON file named myProvisioning.json. Paste the copied content into this file, excluding the last line.
Step 6: Connect to PnP Online
Run the following command to connect to PnP Online:
Connect-PnPOnline -Url "https://test.sharepoint.com/sites/mytest" -Interactive
Enter your credentials when prompted.
Step 7: Get Installed Apps
Run the following command to list the apps installed on your tenant:
Get-PnPApp
Copy the component IDs of the apps you want to include in your template.
Step 8: Add Component IDs to JSON
Add the component IDs to the JSON file in the following format:
{ "verb": "installSolution", "id": "10688609-079b-4b54-aeab-9768be2d7984" }, { "verb": "installSolution", "id": "15368b1d-9ebb-4a94-9920-c57893795441" }, { "verb": "installSolution", "id": "26b0d083-c2a1-4eb7-a070-97c985f0cc6d" }
Paste this at the end of the myProvisioning.json file.
Step 9: Add Site Script
Run the following command to add the site script:
Get-Content "D:\PowerShell Scripts\myProvisioning.json" -Raw | Add-SPOSiteScript -Title "MySiteHomeSiteTemplate"
Copy the ID generated by this command.
Step 10: Add Site Design
Run the following command to add the site design:
Add-SPOSiteDesign
Provide the following details when prompted:
- Title: The name of your template.
- WebTemplate: Use 64 for a team site or 68 for a communication site.
- SiteScripts[0]: Paste the ID generated in Step 9.
Step 11: Apply the Template
To apply the template to a new or existing site:
- Go to the site where you want to apply the template.
- Click on the gear icon and select Site Template.
- Select your template from the list and apply it.
Step 12: Delete an Existing Template
To delete an existing template, run the following command with the specific ID:
Remove-SPOSiteDesign <ID>
For example:
Remove-SPOSiteDesign 21209d88-38de-4844-9823-f1f600a1179a
Conclusion
This guide provides a step-by-step process for site provisioning in SharePoint Online using PowerShell and the PnP module. By following these steps, you can create and apply site templates efficiently.
Comments
Post a Comment