Creating a simple Site Design in SharePoint Online using PowerShell

3 months ago   •   2 min read

By Eric Gregorich

PowerShell can be used to create or update a SharePoint Online Site Design.

Creating a simple Site Design in SharePoint Online using PowerShell

Install the Microsoft.Online.SharePoint.PowerShell module (if not installed).

# Install module
Install-Module -Name Microsoft.Online.SharePoint.PowerShell

Next, update the variables with your information.

[[Define]] Parameters
$AdminCenterURL = "admin-center-url"
$SiteURL = "site-collection-url"

Now connect to SPO with MFA

[[Connect]] to SPO with MFA
Connect-SPOService -Url $AdminCenterURL

Get the site scheme from the configured site.

$SiteSchema = Get-SPOSiteScriptFromWeb -WebURL $SiteURL -IncludeBranding -IncludeTheme -IncludeRegionalSettings -IncludeSiteExternalSharingCapability -IncludedLists ("Shared Documents", "Lists/Demo List 1","Demo Library 1")

Now, add a new Site Script and Site Design.

$SiteScript = Add-SPOSiteScript -Title "Demo Provisioning Template 1" -Content $SiteSchema
$SiteDesign = Add-SPOSiteDesign -Title "Demo Provisioning Template 1" -WebTemplate 64 -SiteScripts $SiteScript.Id

Finally, you can go to the site collection and apply the Site Design manually. Or you can run another script to apply it.

When updating existing Site Designs

You will need to first install the module and connect.

# Install module
Install-Module -Name Microsoft.Online.SharePoint.PowerShell

[[Define]] Parameters
$AdminCenterURL = "admin-center-url"
$SiteURL = "site-collection-url"
  
[[Connect]] to SPO with MFA
Connect-SPOService -Url $AdminCenterURL

Next, you'll need to get the IDs of the Site Script and Site Design you want to update. Run this script and copy the IDs and save them somewhere.

Get-SPOSiteScript
Get-SPOSiteDesign

Now you can run the script get get a fresh Site Script and Site Design then update the existing site design. Don't forget to update the Version for each!

Set-SPOSiteScript -Identity 5337fe68-882b-4e34-98e7-381547170ad9 -Content $SiteSchema -Version 2
$SiteDesign = Set-SPOSiteDesign -Identity 86dcc530-085c-44c5-ae6b-a281ea6c496f -Title "Demo  Site Design" -WebTemplate 64 -SiteScripts $SiteScript.Id -Version 2

Full Script (Execute only the pieces you need)

# Install module
Install-Module -Name Microsoft.Online.SharePoint.PowerShell

[[Define]] Parameters
$AdminCenterURL = "admin-center-url"
$SiteURL = "site-collection-url"
  
[[Connect]] to SPO with MFA
Connect-SPOService -Url $AdminCenterURL
  
# =================================================
[[Get]] the site schema from an existing site
# =================================================
$SiteSchema = Get-SPOSiteScriptFromWeb -WebURL $SiteURL -IncludeBranding -IncludeTheme -IncludeRegionalSettings -IncludeSiteExternalSharingCapability -IncludedLists ("Shared Documents", "Lists/Demo List 1","Demo Library 1")

# =================================================
# Add new Site Design and Scripts
# ================================================= 
$SiteScript = Add-SPOSiteScript -Title "Demo Provisioning Template 1" -Content $SiteSchema
$SiteDesign = Add-SPOSiteDesign -Title "Demo Provisioning Template 1" -WebTemplate 64 -SiteScripts $SiteScript.Id | Grant-SPOSiteDesignRights -Principals ("email-of-account") -Rights View

# =================================================
# Get existing Site Design and Scripts
# ================================================= 
Get-SPOSiteScript
Get-SPOSiteDesign

# =================================================
# Update existing Site Design and Scripts
# ================================================= 
Set-SPOSiteScript -Identity 5337fe68-882b-4e34-98e7-381547170ad9 -Content $SiteSchema -Version 2
$SiteDesign = Set-SPOSiteDesign -Identity 86dcc530-085c-44c5-ae6b-a281ea6c496f -Title "Demo Provisioning Template 1" -WebTemplate 64 -SiteScripts $SiteScript.Id -Version 3 | Grant-SPOSiteDesignRights -Principals ("email-of-account") -Rights View

# =================================================
# Remove existing Site Design and Scripts
# ================================================= 
Remove-SPOSiteScript c0865de9-2ddd-4a9b-b0a3-ee1c52bf1f45
Remove-SPOSiteDesign 3ed718fa-04b9-49e0-999f-c35bccfb5db7

Spread the word

Keep reading