In this tutorial, I will explain how to export and import a SharePoint Online site as a template using PowerShell, along with SharePoint list forms customized using Microsoft Power Apps.
Last week, we received a requirement to migrate one SharePoint Online site from one tenant to another. The source SharePoint Online site contains various lists, list views, libraries, and custom pages. We also customized SharePoint list forms using Power Apps.
Now, we need to implement these changes in the client environment and apply them to the new SharePoint Online site in the destination tenant. I will demonstrate how to migrate a SharePoint site template using PnP PowerShell commands. Please read carefully, as we need to make some changes in the package files.
Export & Import SharePoint Site Template Between Tenants [or Within the Same Tenant] Using PnP PowerShell.
First, let me explain what our source SharePoint Online modern team site contains.
- It contains five SharePoint Online lists.
- Each SharePoint list has many custom views that we created according to business requirements.
- Three list views are also customized or formatted using JSON
- One SharePoint Online list forms are customized using Microsoft Power Apps.
- The SharePoint Site also has a few custom site pages.
You can see the gif image below:

To export and import a SharePoint site between the tenants. We have this “Save site as a template” and “Apply a site template” features. But in modern SharePoint sites, the “Save site as a template” option is not available for several reasons:
- Modern Team sites in SharePoint Online don’t support saving as templates. It is mainly available for classic teams and communication sites.
- If your site has publishing features turned on at the site collection level, you won’t be able to save it as a template due to security restrictions.
- The “Save site as template” won’t be visible if the custom scripts option is restricted.
Even when we enable this “Save site as template” option by allowing custom scripts, you still can’t save it as a template if it has too much content. Modern sites have a size limit of 50 MB for the templates, and any site exceeding this size cannot be saved as a template.
The PnP PowerShell method doesn’t have these restrictions. It allows you to export and import SharePoint site templates, regardless of the site size, making it a more flexible solution for migrating large sites.
NOTE:
These commands extract the SharePoint site’s structure and configuration, such as its lists, libraries, content types, web parts, and customizations (like Power Apps forms and view), rather than the actual data stored in those lists. Follow this approach if your site doesn’t have Power Apps custom forms for SharePoint lists.
Export & Import SharePoint Site Template Using PnP PowerShell [Without Power Apps Custom Form]
The following are the PnP PowerShell commands:
- Get-PnPSiteTemplate
- Invoke-PnPSiteTemplate
Get – PnPSiteTemplate: Used to retrieve the template of a SharePoint site.
Syntax:
Get-PnPSiteTemplate [[-Out] <String>] [[-Schema] <XMLPnPSchemaVersion>] [-IncludeSiteGroups][-PersistBrandingFiles] [-PersistPublishingFiles]- -Out = It specifies the path to save the generated site template file (.xml file).
- -Schema =It defines the schema version for the exported template. The default value is LATEST; it also supports V201503 and V201205 versions, etc.
- -IncludeSiteGroups = This parameter includes the SharePoint site groups in the exported template.
- -PersistBrandingFiles = It includes the branding files, such as the themes used in the site, which are included in the exported template.
- -PersistPublishingFiles = This parameter includes publishing files, such as page layouts, content types, etc, in the exported template.
Here is the PnP PowerShell code:
$SourceSiteURL = "https://<tenant name>.sharepoint.com/sites/ProjectManagement"
# Connect to the source site
Connect-PnPOnline -Url $SourceSiteURL -ClientId "provide your client id" -Interactive
# Export the site template
Get-PnPSiteTemplate -Out "PnP-Provisioning-File.xml" - $SourceSiteURL = Provide your SharePoint site URL.
- In the Connect-PnPOnline cmdlet for -ClientId provide your client id.

Invoke-PnPSiteTemplate: This cmdlet applies a previously exported SharePoint site template to a site, replicating its structure, configurations, and customizations.
Syntax:
Invoke-PnPSiteTemplate [-Path] <String>[-TemplateId <String>][-ClearNavigation]Here:
- -Path = It takes the path to the XML or PnP file containing the provision template.
- -ClearNavigation = It will remove the navigation nodes.
- -TemplateId = Provide Template ID
Here is the PnP PowerShell script to apply the extracted site template to the new SharePoint site.
$TargetSiteURL = "https://<tenant name>.sharepoint.com/sites/ProjectManagementDemo"
# Connect to the destination site
Connect-PnPOnline -Url $TargetSiteURL -ClientId "provide your Client Id" -Interactive
# Now apply the template
Invoke-PnPSiteTemplate -Path "PnP-Provisioning-File.xml" -ClearNavigation- $TargetSiteURL = Provide the new tenant SharePoint site URL where you want to apply the extracted site template. You can also provide the site address, which is present in the same tenant.

The final PowerShell script that will extract and apply the SharePoint site template to the new site.
$SourceSiteURL = "https://<tenant name>.com/sites/ProjectManagementDev"
$TargetSiteURL = "https://<tenant name>.sharepoint.com/sites/ProjectManagementDemo"
# Connect to the source site
Connect-PnPOnline -Url $SourceSiteURL -ClientId "provide your Client Id" -Interactive
# Export the site template
Get-PnPSiteTemplate -Out "PnP-Provisioning-File.xml"
# Connect to the destination site
Connect-PnPOnline -Url $TargetSiteURL -ClientId "provide your Client Id"-Interactive
# List of default system lists to skip
$systemLists = @(
"Site Pages", "Documents", "AppData", "User Information List",
"Master Page Gallery", "Style Library", "Theme Gallery",
"Solution Gallery", "TaxonomyHiddenList", "Web Part Gallery"
)
# Check if a list exists before creating it
Get-PnPList | ForEach-Object {
if ($systemLists -notcontains $_.Title) {
Write-Host "Skipping system list: $($_.Title)"
} else {
Write-Host "List exists: $($_.Title)"
}
}
# Now apply the template (if list doesn't exist or you have already removed unnecessary ones)
Invoke-PnPSiteTemplate -Path "PnP-Provisioning-File.xml" -ClearNavigation
Write-Host "Template applied successfully"In this script, I’m avoiding adding the default lists that will be created when a new SharePoint site is created. I’m storing those in the $systemLists array. Before invoking only, I’m skipping the default lists so it won’t add.
Here’s the new SharePoint site that invokes the template from the old SharePoint site, which contains all the lists, their views, site pages, and other content. But it won’t take the data into the SharePoint lists.

NOTE:
If your SharePoint Online site includes any Power Apps form for lists, please follow the below section to ensure that the Power Apps custom form works correctly on the new site after migration.
Export & Import SharePoint Site Template Using PnP PowerShell [With Power Apps Custom Form]
When replicating an old site template into a new site using PnP PowerShell, the Power Apps custom form for lists may continue to reference the old site. This occurs because the migration does not update the SharePoint site address or list ID URLs in the Power Apps form.
As a result, in the List Settings -> Form Settings, the option “Use a custom form created in PowerApps” is disabled, while only the default SharePoint form option is enabled. Clicking the “Customize in PowerApps” option may still open the form tied to the old site.

To resolve this, you’ll need to take a backup of the Power Apps custom form as a zip file from the old SharePoint site. Then delete it, before saving it as a template with PowerShell cmdlets.
- Open the old SharePoint site ->List ->List setting ->Form setting->Click See versions and usage.

- It opens the Power Apps details pane, and click on the ->Export package.

- Provide the package name and description, then under IMPORT SETUP ->Click Update ->Create as a new. -> Under ACTION, click on the icon ->Again choose ->Create as a new ->Click on Export.
Note: Don’t navigate away while exporting. Then, it will download the package to your local system.

- We have the package, so we’ll delete this Power Apps custom form from the old SharePoint site. Again, open the Form setting in the old SharePoint list settings. Choose the “Use the default SharePoint form” option -> Click on Delete custom form, and delete it.

- The Power Apps custom form has been deleted from the old SharePoint site. Now, use the code below to extract and apply the SharePoint site template from the old site to the new site.
$SourceSiteURL = "https://<tenant name>.com/sites/ProjectManagementDev"
$TargetSiteURL = "https://<tenant name>.sharepoint.com/sites/ProjectManagementDemo"
# Connect to the source site
Connect-PnPOnline -Url $SourceSiteURL -ClientId "provide your Client Id" -Interactive
# Export the site template
Get-PnPSiteTemplate -Out "PnP-Provisioning-File.xml"
# Connect to the destination site
Connect-PnPOnline -Url $TargetSiteURL -ClientId "provide your Client Id"-Interactive
# List of default system lists to skip
$systemLists = @(
"Site Pages", "Documents", "AppData", "User Information List",
"Master Page Gallery", "Style Library", "Theme Gallery",
"Solution Gallery", "TaxonomyHiddenList", "Web Part Gallery"
)
# Check if a list exists before creating it
Get-PnPList | ForEach-Object {
if ($systemLists -notcontains $_.Title) {
Write-Host "Skipping system list: $($_.Title)"
} else {
Write-Host "List exists: $($_.Title)"
}
}
# Now apply the template (if list doesn't exist or you have already removed unnecessary ones)
Invoke-PnPSiteTemplate -Path "PnP-Provisioning-File.xml" -ClearNavigation
Write-Host "Template applied successfully"Provide the URLs of your source and target sites for the variables and client IDs for the sites in the above code.
After applying the extracted site template to the new SharePoint site, follow the steps below.
- Let’s see how to import the Power Apps custom form into the new SharePoint site. Before that, open the new SharePoint site ->List ->List settings ->Copy list ID from the URL, and SharePoint site address and Web address, then paste it into a notepad.
- site id = “https://tenantname.sharepoint.com/sites/sitename”
- list id = From URL take the id between %7B and % 7D.
- list URL = copy Web Address.

- Extract the downloaded zip file ->Open Microsoft.PowerApps folder -> apps folder -> Numberfolder[983254726562654] -> Open numbers.json file in VS code -> Format the json code.

Update the connections below with the IDs and URLs you copied earlier.
- site id = SharePoint site URL “https://tenant name.sharepoint.com/sites/sitename”
- list id = ID between %7B and %7D from the url.
- list URL = Web Adress.
Save the changes and double-check that the URLs are updated in the JSON file.
- Make the Microsoft.PowerApps folder and manifest json file as a compressed zip file, like in the below. Change the zip file name for easy identification.

- Open the Power Apps platform ->Click on Import App -> Choose From package (.zip).

- In the Import Package page, click on the Upload button to upload the zip file -> Click on Update -> Change the app name,-> Also, click on the action icon to change the app name and save it. Click on Import.

- Then click on the Open app. It opens the Power Apps custom form; remove the data source and add your new Sharepoint site list name. Then, save and publish the changes.

- Open the new SharePoint site and open the list, click on the +Add new item. It opens the Power Apps custom form, tries to add and save data, and then it saves to the current list.

This way, we can import the Power Apps custom form into the new SharePoint site after applying the old SharePoint site template.
I hope you understand how to replicate the old SharePoint site template into the new SharePoint site. In this article, I also explained how to export and import the Power Apps custom form from the old site to the new site to avoid issues during replication.
Also, you may like:
- How to create a list view in SharePoint Online?
- SharePoint modern list column formatting.
- How to change the SharePoint site collection URL
- Embed PowerPoint slide in SharePoint
- SharePoint list permissions

After working for more than 18 years in Microsoft technologies like SharePoint, Microsoft 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (12 times). I have also worked in companies like HP, TCS, KPIT, etc.