Saturday, March 8, 2025

Powershell - Create a Site Template

 # ref https://pnp.github.io/powershell/cmdlets/index.html

# Variables for site URL and site name

$tenantId = "u7ub14b9-dc5c-44fe-a920-7e6bb7e310a6"
$tenantUrl = "https://[tenant].sharepoint.com"
$siteUrl = "https://[tenant].sharepoint.com/sites/DesignSite"
# set script id to output of Add-PnPSiteScript
$scriptId = "06763a50-0f1b-4a01-b7d6-a7c2fd54703a"

Connect-PnPOnline -Url $siteUrl -Tenant $tenantId -Interactive -ClientId c544a357-50a0-4ce9-99f8-79fc70fc8478

# check if working
Get-PnPTenantSite
Get-PnPConnection
# set site for future work, should be set from connect-pnponline

# get site script for template
$siteJson = Get-PnPSiteScriptFromWeb -IncludeAll

Add-PnPSiteScript -Title "Org Intranet" -Content $siteJson -Description "Org Intranet Site Template"

#set sciptId to output of Add-PnPSiteScript
$scriptId = "06763a50-0f1b-4a01-b7d6-a7c2fd54703a"  # output of Add-PnPSiteScript

Add-PnPSiteDesign -Title "Org Template 2" -SiteScriptIds $scriptId -Description "Org Template 2" -WebTemplate "68"

# check if it worked, look for the ID returned from Add-PnPSiteDesign or the Title used

Get-PnPSiteDesign

# switch site once logged in with
Connect-PnPOnline -Url "https://1495304ab.sharepoint.com/sites/TemplateSite03" -UseWebLogin

# set logo
$logoUrl = "https://[tenant].sharepoint.com/sites/DesignSite/SiteAssets/tgicon.png"
Set-PnPWeb -SiteLogoUrl $logoUrl

No comments:

Post a Comment