The Wild

PnP Provisioning Engine Content Migration Guide

· 6 min read · Mammals

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Migrating content with the PnP Provisioning Engine allows you to extract the structure, configuration, and content of a SharePoint site and apply it to another site or environment. This process achieves a consistent deployment of site templates, lists, libraries, and page layouts, ensuring that the destination environment mirrors the source exactly. This is particularly useful for moving a developed "golden template" from a sandbox to a production tenant or duplicating complex site architectures across multiple team sites.

What You'll Need

  • PowerShell installed on your local machine (Windows PowerShell 5.1 or PowerShell 7).
  • The PnP PowerShell module installed (Install-PnP.PowerShell).
  • Administrative permissions on both the source and destination SharePoint sites (Site Collection Administrator).
  • An App Registration in Azure Active Directory (Microsoft Entra ID) with the necessary API permissions (Sites.FullControl.All) to allow the PnP module to authenticate and modify site content.
  • A local folder to store the exported XML templates and associated files.

Step-by-Step

  1. Install and Initialize PnP PowerShell: Open your PowerShell terminal as an administrator. If you haven't already, install the module by running Install-Module PnP.PowerShell. Verify the installation by checking the version to ensure you are using the latest stable release, as the provisioning engine is frequently updated to support new SharePoint Online features.
  2. Connect to the Source Site: Use the Connect-PnPOnline command to authenticate with your source site. It is recommended to use the -Interactive switch or a registered App ID for seamless authentication. Ensure you are connected to the specific site collection that contains the content you wish to migrate.
  3. Extract the Site Template: Run the Get-PnPSiteTemplate command. This is the core of the provisioning engine. You can specify exactly what to extract using parameters. For example, to capture everything including lists, fields, and pages, use Get-PnPSiteTemplate -Out "template.xml". If you only need specific components, you can use the -Handlers parameter to limit the extraction to only "Lists" or "Fields," which reduces the size of the XML file and speeds up the deployment process.
  4. Review and Edit the XML Template: Open the generated template.xml file in a text editor like VS Code. Review the XML to ensure no environment-specific hardcoded IDs (such as specific user IDs or absolute URLs) are present that might cause conflicts in the destination site. While the PnP engine handles many mappings automatically, manually verifying the site's internal names and GUIDs can prevent deployment errors.
  5. Connect to the Destination Site: Disconnect from the source site and use Connect-PnPOnline to connect to the target site. Ensure the destination site exists; the provisioning engine applies templates to an existing site rather than creating a new site collection from scratch.
  6. Apply the Template: Execute the Invoke-PnPSiteTemplate command, pointing it to your XML file: Invoke-PnPSiteTemplate -Path "template.xml". The engine will now read the XML and begin recreating the lists, libraries, content types, and page layouts in the destination environment.
  7. Migrate the Actual File Content: It is critical to understand that Get-PnPSiteTemplate extracts the structure (schema) and not the data (files and list items). To move the actual documents and list entries, you must use separate commands such as Get-PnPFile and Add-PnPFile, or utilize a migration tool like the SharePoint Migration Tool (SPMT) in conjunction with the PnP template to ensure the structure is ready before the data arrives.
  8. Verify the Deployment: Navigate to the destination site and manually check that the lists are created with the correct columns, the navigation is intact, and the page layouts are functioning as expected. Test the permissions and ensure that the content types are correctly associated with the libraries.

Common Mistakes

One of the most frequent errors is confusing provisioning with migration. Users often expect Get-PnPSiteTemplate to move thousands of documents and list items. In reality, the provisioning engine is designed for structural deployment. If you rely solely on the XML template, you will find your destination site has all the right columns and folders, but no actual data inside them.

Another common mistake is ignoring the "Handler" settings. Attempting to export a massive site with every single handler enabled can lead to timeouts or overly bloated XML files that are difficult to debug. It is better to export in modules—first the site columns and content types, then the lists, and finally the pages.

Authentication failures are also common, particularly when moving between different tenants. Users often forget that the App Registration used for the source tenant will not work for the destination tenant. You must ensure that the destination tenant has a corresponding App Registration with the correct permissions granted and consented to by a Global Administrator.

Tips

To make your templates more portable, use the -IncludeSiteSettings parameter. This ensures that site-level configurations, such as regional settings and feature activations, are captured along with the structural components. This prevents the "missing feature" errors that often occur when a template expects a specific SharePoint feature to be active on the destination site.

For complex migrations, implement a "staged deployment" approach. Instead of one giant XML file, create multiple smaller files (e.g., Columns.xml, Lists.xml, Pages.xml). Apply them in that specific order. This allows you to isolate errors; if the Pages.xml fails, you know the lists and columns were already successfully deployed, and you only need to troubleshoot the page-related XML.

Utilize the -Handlers parameter to exclude unnecessary system lists. By excluding the "Style Library" or "Site Assets" if they aren't being customized, you can keep your template clean and reduce the risk of overwriting default system files in the target environment.

Troubleshooting

If you encounter a "403 Forbidden" error during the Invoke-PnPSiteTemplate process, the most likely cause is insufficient permissions. Verify that the account or App ID you are using is a Site Collection Administrator on the destination site. Even if you are a Tenant Admin, some site-level security settings can block PnP operations if you aren't explicitly added to the site's admin group.

When you see an error stating that a "Content Type already exists," it usually means you are applying a template to a site that isn't completely empty. The provisioning engine can sometimes struggle to overwrite existing content types. To fix this, either delete the conflicting content type from the destination site before running the command or use the -Force parameter (where available) to overwrite existing configurations.

If the template applies successfully but pages appear blank or broken, check the absolute URLs within the XML. If the source site was /sites/dev-site and the destination is /sites/prod-site, any hardcoded links to images or scripts in the page content will still point to the dev site. You will need to use a find-and-replace tool in your XML editor to update these URLs to match the destination site's path before applying the template.

Frequently Asked Questions

Does PnP Provisioning migrate user permissions?

No, the provisioning engine does not migrate specific user permissions or group memberships, as these are tied to the unique User IDs of the specific tenant. You must re-assign permissions on the destination site.

Can I use this to move content between different Microsoft 365 tenants?

Yes, you can extract a template from one tenant and apply it to another, provided you have the necessary authentication and permissions set up in both environments.

How do I migrate the actual files inside a library?

The PnP Provisioning Engine only moves the library structure. To move the files, use Get-PnPFile and Add-PnPFile in a loop, or use the SharePoint Migration Tool (SPMT) for large volumes of data.

What is the difference between a PnP Template and a Site Design?

PnP Templates are XML-based files managed via PowerShell for granular control. Site Designs (and Site Scripts) are the native Microsoft 365 way to apply templates via the UI or JSON scripts.

Can I migrate only one specific list using this method?

Yes, by using the -Handlers parameter and specifying the list name, you can export and import a single list without affecting the rest of the site structure.