SharePoint PnP Provisioning with Data – Move Your Contents from One Site to Another in SharePoint Online

SharePoint PnP Provisioning Commands

[toc]

Introduction

I understand that you need to move all of your contents to your destination site from your source site in SharePoint online. You might have done some search in Google and saw this post. Here in this article, I will be walking you through the steps you need to perform the SharePoint PnP provisioning. With the latest SharePoint modern experience, Microsoft had decided to turn off some features, and one among them was Custom Scripting. Unfortunately, to do the SharePoint provisioning, we will have to enable the Custom Scripting. Enough talking, let’s jump into the coding. I hope you will find this post useful.

Before you start Provisioning your site

Before you jump into the process of provisioning there is some configuration which you must perform.

  • Enable the Custom Scripting
  • Set the User as a Term Store Admin

Enable the Custom Scripting

With the latest release, Microsoft had deactivated this feature from the modern SharePoint experience thus we would have to enable it manually. According to Microsoft, below are the features which will not be available until you manually enable the custom scripting.

  1. Save Site as Template
  2. Save document library as template
  3. Solution Gallery
  4. Theme Gallery
  5. Help Settings
  6. HTML Field Security
  7. Sandbox solutions
  8. SharePoint Designer
  9. Uploading files that potentially include script

In our case, we wanted to do SharePoint PnP provisioning, and it is interesting that it is not mentioned anywhere that we need to enable custom scripting to do SharePoint PnP provisioning. You can always enable the Custom Scripting in two ways, one is using the portal, and another is to use PowerShell commands. I would prefer using the PowerShell commands as it will enable the custom scripting right away. If you enable the custom scripting via the portal, it will take 24 hours to get it activated.

To allow custom script on other SharePoint site collections, you will have to download the download the latest SharePoint Online Management Shell. Once you are done you can perform the below commands.

Connect-SPOService -Url https://yoursharepoint-admin.sharepoint.com

The above command will connect your SharePoint admin site, please be noted that you should have a tenant admin access to do this. If you don’t have the access, you should consider getting the access or you can request the tenant admin to do the same.

Once you are connected, you can perform the preceding command.

Set-SPOsite https://yoursharepinttenant.sharepoint.com/sites/yoursharepointsite -DenyAddAndCustomizePages 0

The above command will enable the custom scripting for the site you have mentioned. To check this, you can always go to any of your site collection/list settings, and if you see the option save the list as a template, it is done and you can proceed.

Save list as template

Save list as the template

Set the User as a Term Store Admin

Once we have enabled the custom scripting it is time to add you as the Term Store Admin, again you can always reach out to your Tenant admin to add you as a Term Store Admin. You can ask your Tenant admin to perform the preceding steps.

  1. Sign in to Office 365 as a global admin or SharePoint admin.

  2. Click on the app launch icon( 9 dots) and then click on Admin to open the Microsoft 365 admin center.
  3. Select Admin centers and then click on SharePoint.
  4. Now, you should see an option as Term Store and click on it.
  5. He/She can add your mail id in the text box near to the heading Term Store Administrators

Once it is done you can always go to your Site Settings > Term Store Management > Term Store Administrators.

Start SharePoint PnP Provisioning

Wow!. We have done all the configuration and now we can start doing the provisioning.

Connect your source site

The first thing to do is, to connect the source SharePoint site, you can do that by using the preceding command.

Connect-PnPOnline https://youradmin.sharepoint.com/sites/yoursite/

Generate a provisioning template

Now we can generate a provisioning template from the web. You can do that by doing the command below.

Get-PnPProvisioningTemplate -Out c:/Provisioning/template.xml

Please be noted that this will create a new folder “Provisioning” in the C drive and then place the template.xml in it. You can always see the other options of Get-PnPProvisioningTemplate here. This command will pull almost everything from the source site, and you can always choose what exactly you need to take from the source site. This will not retrieve the data, you will have to use another command for that.

Add data to the provisioning template

As we have seen that the Get-PnPProvisioningTemplate will not retrieve the data with the list, we will have to use Add-PnPDataRowsToProvisioningTemplate command to do that magic.

Add-PnPDataRowsToProvisioningTemplate -Path c:/Provisioning/template.xml -List 'The list name' -Query '<view></view>'

Please see here to see the other options you can use with the Add-PnPDataRowsToProvisioningTemplate command. Please be noted that the size of the template.xml file will be larger as per the data you have in the source list.

Apply provision to your destination site

Now we have an XML file which has everything we need to move. Let’s just do it then. Connect your destination site by following the command below.

Connect-PnPOnline https://youradmin.sharepoint.com/sites/yourdetinationsite

Please remember to use the same id and password of your Term Store Admin account.

Once you are connected to the destination site, you can perform the Apply-PnPProvisioningTemplate as follows.

Apply-PnPProvisioningTemplate -Path C:/Provisioning/template.xml

If you are getting an error as ” Apply-PnPProvisioningTemplate : The parent content type specified by content type identifier does not exist”, you will have to enable the SharePoint Server Publishing feature in the Site Settings > Site Features. Remember to enable the SharePoint Server Publishing Infrastructure under Site Settings > Site Collection Features before you enable the SharePoint Server Publishing feature in the Site Settings. It is a dependency. You can always see my StackExchange answer here.

Apply-PnPProvisioningTemplate : The parent content type specified by content type identifier does not exist.
At line:1 char:1
+ Apply-PnPProvisioningTemplate -Path C:\Provisioning\template.xml
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Apply-PnPProvisioningTemplate], ServerException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Provisioning.ApplyProvisioningTemplate

Please be noted that you will also get an error as “WARNING: ListInstance Style Library is a Style Library of a site with NoScript enabled and will be skipped” if the custom scripting is not enabled.

You will also get an error as “Access denied. You do not have permission to perform this action or access this resource” if you don’t have Term Store Admin permission.

Apply-PnPProvisioningTemplate : Access denied. You do not have permission to perform this action or access this resource.
At line:1 char:1
+ Apply-PnPProvisioningTemplate -Path C:/Provisioning/template.xml
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Apply-PnPProvisioningTemplate], ServerUnauthorizedAccessException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Provisioning.ApplyProvisioningTemplate

Once you run the Apply-PnPProvisioningTemplate command, and if everything is fine, you will get everything in your destination site. It will take some time to generate everything for you and add the data to it, depends on the amount of the data you have the process can take from 5 minutes to hours.

Conclusion

Congratulation, we have successfully moved all of our data and almost everything from one SharePoint site to other. In this article, we have learned how to,

  1. Enable Custom Scripting in SharePoint
  2. Add a Term Site Admin
  3. Connect to a SharePoint site
  4. Create a PnP provisioning template from the web
  5. Add data to your Provisioning template form the lists
  6. Apply the provisioning to the destination SharePoint site

Your turn. What do you think?

Thanks a lot for reading. I will come back with another post on the same topic very soon. Did I miss anything that you may think which is needed? Could you find this post as useful? Kindly do not forget to share me your feedback.

Kindest Regards
Sibeesh Venu

Leave a Reply

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

Serverless 360