Exporting and Importing SharePoint Site Templates using PnP PowerShell

Loading

Exporting and importing SharePoint site templates allows you to replicate site structures, lists, libraries, settings, and workflows across multiple sites. This is useful for site standardization, migration, or disaster recovery.

What Can Be Exported?
✔ Site structure (lists, libraries, columns, content types)
✔ Navigation settings
✔ Security settings (permissions, groups)
✔ Workflows and features


Step 1: Install & Connect to SharePoint Online

First, ensure that PnP PowerShell is installed:

Install-Module -Name PnP.PowerShell -Scope CurrentUser -Force

Connect to the source SharePoint site:

$SourceSite = "https://yourtenant.sharepoint.com/sites/SourceSite"
Connect-PnPOnline -Url $SourceSite -Interactive

Successfully connected to the source site!


Step 2: Export a SharePoint Site Template

Now, export the site structure to an XML file.

$TemplatePath = "C:\Templates\SiteTemplate.xml"

# Export site template
Get-PnPSiteTemplate -Out $TemplatePath -Handlers Lists,Fields,ContentTypes,Security,Features

Write-Host "✅ Site template exported to: $TemplatePath"

Explanation

  • -Out $TemplatePath → Saves the template as an XML file
  • -Handlers Lists,Fields,ContentTypes,Security,Features → Specifies what to export
  • The file can be used to create similar sites later.

Step 3: Create a New SharePoint Site

Before importing, create a new SharePoint site where the template will be applied.

$NewSiteUrl = "https://yourtenant.sharepoint.com/sites/DestinationSite"
$NewSiteTitle = "Destination Site"

# Create a new Communication site
New-PnPSite -Type CommunicationSite -Title $NewSiteTitle -Url $NewSiteUrl -Owner "admin@yourtenant.onmicrosoft.com"

Write-Host "✅ New site created: $NewSiteUrl"

The new SharePoint site is ready!


Step 4: Import the Site Template into the New Site

Now, apply the exported template to the new SharePoint site.

Connect-PnPOnline -Url $NewSiteUrl -Interactive

Apply-PnPSiteTemplate -Path $TemplatePath

Write-Host "✅ Site template applied successfully!"

What Happens?

✔ Lists and libraries are created
✔ Content types and metadata are restored
✔ Site settings and navigation are configured

The new site now matches the original site!


Step 5: Verify and Adjust Settings

After importing the template, double-check the following:
Lists & Libraries: Ensure all columns and settings are applied
Permissions: Assign proper user access
Navigation: Fix missing links if necessary

To view all lists in the new site:

Get-PnPList | Select Title, ItemCount

To view applied site features:

Get-PnPFeature

Bonus: Automate the Process with a PowerShell Script

To automate site template exporting and importing, create a script:

$SourceSite = "https://yourtenant.sharepoint.com/sites/SourceSite"
$DestinationSite = "https://yourtenant.sharepoint.com/sites/DestinationSite"
$TemplatePath = "C:\Templates\SiteTemplate.xml"

# Connect to the source site
Connect-PnPOnline -Url $SourceSite -Interactive

# Export the template
Get-PnPSiteTemplate -Out $TemplatePath -Handlers Lists,Fields,ContentTypes,Security,Features
Write-Host "✅ Site template exported!"

# Connect to the destination site
Connect-PnPOnline -Url $DestinationSite -Interactive

# Apply the template
Apply-PnPSiteTemplate -Path $TemplatePath
Write-Host "✅ Template applied successfully!"

This script automates the entire process!

Leave a Reply

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