In this article, we will explore PnP Provisioning template process and how we can leverage this provisioning template to migrate SharePoint Online/Office 365 Site collections.

Pre-requisite is to Install the latest SharePointPnPPowerShellOnline.msi from location


We will need to divide overall process in to 5 steps as below: 

  • Download artifacts from existing site.
  • Download PnP Provisioning template from existing site.
  • Modify PnP Template to include downloaded artifacts and change old site references.
  • Create Site Structure.
  • Apply PnP Provisioning template to destination site.

In this article, We will cover first 2 elements of the process. 
For reference, We will use “C:\Scripts” as local folder.

Download Artifacts

In case of migration, we need to not only take care of the site structure/lists/settings/template but also the files and content in those lists. When we get the PnP Provisioning template using its PowerShell commands, it only extracts its empty site template without contents.

For migration of content, we need to download this content locally and include in Provisioning template.
For example: Let say we have a lot of documents in ‘Document’ library which we need to migrate.

Power Shell Steps will be: 

  • Get Credentials 
$credentials = Get-Credential 
  • Connect to SharePoint Online

-          Connect-PnPOnline -Url $sourceUrl -CreateDrive -Credentials $credentials 

  • Connect to Site Collection OR sub site
  • Create drive
This step is very crucial, SPO:\ is drive which SharePoint online create when “-CreateDrive” parameter is used while connecting SharePoint Online. Also if we have a sub site which contain contents e.g. “/sites/demosite” then we need to append its relative path to SPO:\ . 

$sourceMappedLocation = 'SPO:\'
if($subSiteRelativePath -ne "")
 $sourceMappedLocation = 'SPO:\' + $subSiteRelativePath
  • Go to path in SharePoint Online.
Using the below path, we are inside the SharePoint Online driver location and we can see all libraries as folder. 

cd $sourceMappedLocation 
  • Copy files to local

$FolderDocuments = $Folder +'C:\Scripts\Staging\Documents\' 
Copy-PnpItemProxy  -force  -r 'Documents\' $FolderDocuments 

These commands will download all files in the ‘Documents’ folder to C:\Scripts\Staging\Documents. I am keeping one ‘Staging’ folder so that I can segregate files from my Scripts in C:\Scripts,

In case of multiple libraries, we will need to do this process multiple times. Identify which all libraries need to be migrated and keep them in different folders.

Copy-PnpItemProxy -force  -r 'Banner\' $FolderBanner
Copy-PnpItemProxy  -force  -r 'Documents\' $FolderDocuments
Copy-PnpItemProxy  -force -r 'Resources\' $FolderResources 


 We will need to go to sub-site path to use Copy-PnpItemProxy function. If it’s multiple sub site, then we need to do ‘cd $sourceMappedLocation’ to go in each sub site.

cd SPO:\sites\site1
Copy-PnpItemProxy -force -r 'Documents\' “C:\Scirpts\Staging\site1\Documents”

cd SPO:\sites\site2
Copy-PnpItemProxy -force -r 'Documents\' “C:\Scirpts\Staging\site2\Documents”
Copy-PnpItemProxy -force -r ' Resources\' “C:\Scirpts\Staging\site2\Resources”

This will only copy files and will not maintain its version.

Get PnP Provisioning Template

Now we have downloaded all the required artifacts and ready to get PnP Provisioning template. As such it’s a very simple command line. 

Connect-PnPOnline -Url $sourceUrl -CreateDrive -Credentials $credentials

md ‘c:\Scripts\site1’ -ErrorAction Ignore

cd ‘c:\Scripts\site1’

Get-PnPProvisioningTemplate -Out 'site1Template.xml' -IncludeSiteCollectionTermGroup -IncludeNativePublishingFiles -IncludeSearchConfiguration -PersistBrandingFiles -PersistPublishingFiles -FORCE -Verbose -Debug

But we n
eed to be very careful as to what all parameters we need to include. Here is list of all the parameters   

Using the above command, it will download provisioning template with the Master pages and ‘default.aspx’. Above, I have gone to the folder location and extracted the template. Similarly, we will need to go to each sub sites and get its template. 

md ‘c:\Scripts\site1’ -ErrorAction Ignore
cd ‘c:\Scripts\site1’
Get-PnPProvisioningTemplate -Out 'site1Template.xml' -IncludeSiteCollectionTermGroup -IncludeNativePublishingFiles -IncludeSearchConfiguration -PersistBrandingFiles -PersistPublishingFiles -FORCE -Verbose -Debug
 md ‘c:\Scripts\site1\subsite’ -ErrorAction Ignore
cd ‘c:\Scripts\site1\subsite’
Get-PnPProvisioningTemplate -Out 'subsiteTemplate.xml' -IncludeSiteCollectionTermGroup -IncludeNativePublishingFiles -IncludeSearchConfiguration -PersistBrandingFiles -PersistPublishingFiles -FORCE -Verbose -Debug
 md ‘c:\Scripts\site2’ -ErrorAction Ignore
cd ‘c:\Scripts\site2’
Get-PnPProvisioningTemplate -Out 'site2Template.xml' -IncludeSiteCollectionTermGroup -IncludeNativePublishingFiles -IncludeSearchConfiguration -PersistBrandingFiles -PersistPublishingFiles -FORCE -Verbose -Debug

In the next article, we will cover how to modify extracted PnP template to include downloaded artifacts, references and apply this to a new site collection.