Copy SPO team site with task list contens/row data

Christoph Maerz 21 Reputation points
2020-12-27T22:57:16.557+00:00

Hi,

I use a Sharepoint Online Hub to organize very similar projects, with one hub site and the projects are added as team sites. The most important part is the task list with many already filled items which are exactly the same for all projects.
What is the easiest way to copy a Site with all its contents to another site?

I tried Get-PnPProvisioningTemplate with Add-PnPDataRowsToProvisioningTemplate and there was nor error message but the tasklist was still empty.

Add-PnPDataRowsToProvisioningTemplate -Path template.pnp -List 'PnPTestList' -Query '' -IncludeSecurity

Does anybody have experience how to completely copy a sharepoint team site?

Thanks
Chris

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,685 questions
0 comments No comments
{count} votes

Accepted answer
  1. Echo Du_MSFT 17,161 Reputation points
    2020-12-28T02:43:47.883+00:00

    Hello @Christoph Maerz ,

    Here is how you can Copy List or Document Library to Another Site using PnP PowerShell.

    Step 1: Get the List Schema from Source Site

    #Config Variables  
    $SiteURL = "https://test.sharepoint.com/sites/source/"  
    $ListName = "Project Tasks"  
    $TemplateFile = "C:\Temp\ListSchema.xml"  
           
    #Connect to PNP Online  
    Connect-PnPOnline -Url $SiteURL -UseWebLogin  
           
    #Get the List schema as Template and export to a File  
    $Templates = Get-PnPProvisioningTemplate -OutputInstance -Handlers Lists  
    $ListTemplate = $Templates.Lists | Where-Object { $_.Title -eq $ListName }  
    $Templates.Lists.Clear()  
    $Templates.Lists.Add($ListTemplate)  
    Save-PnPProvisioningTemplate -InputInstance $Templates -Out $TemplateFile  
    

    Step 2: Apply the Template in the Target Site

    #Config Variables  
    $SiteURL = "https://test.sharepoint.com/sites/destination/"  
    $TemplateFile = "C:\Temp\ListSchema.xml"  
       
    #Connect to PNP Online  
    Connect-PnPOnline -Url $SiteURL -UseWebLogin  
       
    Write-Host "Creating List from Template..."  
    Apply-PnPProvisioningTemplate -Path $TemplateFile  
    

    Thanks,
    Echo Du

    ————————————————Updated Answer————————————————

    Hi @Christoph Maerz ,

    • Add-PnPDataRowsToProvisioningTemplate -Path template.pnp -List 'PnPTestList' -Query '' -IncludeSecurity

    The fields to retrieve. If not specified all fields will be loaded in the returned list object. But some specific fields will not be loaded, such as ID.

    So, I suggest you can enter the column name of the field you want.

    For example:

    • Add-PnPDataRowsToProvisioningTemplate -Path template.pnp -List 'PnPTestList' -Query '' -Fields 'Title','Choice' -IncludeSecurity

    Complete code:

     #Config Variables  
     $SiteURL = "https://test.sharepoint.com/sites/source/"  
     $ListName = "Alert"  
     $TemplateFile = "C:\Temp\template.pnp"  
               
     #Connect to PNP Online  
     Connect-PnPOnline -Url $SiteURL -UseWebLogin  
               
     #Get the List schema as Template and export to a File  
     $Templates = Get-PnPProvisioningTemplate -OutputInstance -Handlers Lists  
     $ListTemplate = $Templates.Lists | Where-Object { $_.Title -eq $ListName }  
     $Templates.Lists.Clear()  
     $Templates.Lists.Add($ListTemplate)  
     Save-PnPProvisioningTemplate -InputInstance $Templates -Out $TemplateFile  
     Add-PnPDataRowsToProvisioningTemplate -Path $TemplateFile -List 'Alert' -Query '' -Fields 'Title','Name','Name(hide)','Status'   
      
     #Config Variables  
     $SiteURL = "https://test.sharepoint.com/sites/destination/"  
     $TemplateFile = "C:\Temp\template.pnp"  
           
     #Connect to PNP Online  
     Connect-PnPOnline -Url $SiteURL -UseWebLogin  
           
     Write-Host "Creating List from Template..."  
     Apply-PnPProvisioningTemplate -Path $TemplateFile  
    

    52234-3.png
    52235-1.png

    Thanks,
    Echo Du

    ===============================
    Updated Answer ===================================

    Hi @Christoph Maerz ,

    It is recommended that you consider the out-of-the-box function to achieve your design.

    step1: Export template

    • Sign in the source Task list as an admin and click on List Settings
    • On the List Settings page, click on Save list as template
      Note: Please select the Include Content checkbox to store items
      53039-1.png
    • Go to Site settings page, click on List template under the Web Designer Galleries. Here you can see the template you just created.
    • Then select this template, and then click on Download a Copy on the FILES tab
      53040-2.png

    step2: Import template

    • Sign in the destination site collection as an admin and go to Site settings page
    • On the Site settings page, click on List template under the Web Designer Galleries.Then, click on Upload Document on the FILES tab to import the template you just downloaded
      53130-3.png

    step3: Create a App

    • Go to Site contents page(destination site collection), create a new App, you can retrieve the template you just imported and use it.
      Note: The value of the Person or Group column can not copy
      53075-6.png

    Thanks,
    Echo Du

    ========================

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

7 additional answers

Sort by: Most helpful
  1. Christoph Maerz 21 Reputation points
    2020-12-28T08:20:51.813+00:00

    Hi Echo,

    thank for your reply. The scripts are nice and are almost the same what I did step by step, but my main problem is still, that only the lists are created, but not the data rows that already exists in the source are copied. Although I am getting this error when applying the template, but I have to look deeper into that:

    Apply-PnPProvisioningTemplate : Die Spalte 'Description' ist nicht vorhanden. Möglicherweise wurde sie von einem anderen Benutzer gelöscht.
    In C:\Temp\Apply Lists to Template.ps1:10 Zeichen:2

    • Apply-PnPProvisioningTemplate -Path $TemplateFile
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : WriteError: (:) [Apply-PnPProvisioningTemplate], ServerException
    • FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Provisioning.Site.ApplyProvisioningTemplate

    That's what I thought was Add-PnPDataRowsToProvisioningTemplate for, but it just does not work for me.

    Do you know what I mean?


  2. Christoph Maerz 21 Reputation points
    2020-12-29T05:39:35.3+00:00

    I know, but that's not what i want, I also wan't the content/items/tasks of the list in the new list.

    This is what Add-PnPDataRowsToProvisioningTemplate is for, but it's not working for me.

    Have you used Add-PnPDataRowsToProvisioningTemplate and it worked?


  3. Christoph Maerz 21 Reputation points
    2020-12-29T23:40:41.963+00:00

    Hi,

    ok, so I see your pictures and that works fine for me for regular lists, but it's not really working for tasks. I got it to but not with all fields. When i use:

    Add-PnPDataRowsToProvisioningTemplate -Path $TemplateFile -List $ListName -Query '' -Fields 'DueDate' -IncludeSecurity
    

    It adds the Data rows only with the DueDate field/column. In the documentation of Add-PnPDataRowsToProvisioningTemplate for the parameter fields is written:

    The fields to retrieve. If not specified all fields will be loaded in the returned list object.
    

    But that does not work for me. When I add the other column names (in englisch from the XML file) it still doesn't work for me.
    I found a similar problem on the GitHup site: https://github.com/pnp/PnP-Sites-Core/issues/1838
    The solve this with and the json file, but still I don't know which fields to specify in the .jason file.

    Get-PnPProvisioningTemplate -Configuration "config.json" -out $templatePath
    

    So let me specify my question: Do you know how to use Add-PnPDataRowsToProvisioningTemplate for a task list (added via apps>tasks)?

    I appreciate your help so far, i think/hope I am getting closer to a solution. I'm just very surprised that I can't really find any solution on the web for it, because I would guess that this is a pretty common use case. I mean reusing defined task lists. Or I am wrong?


  4. Christoph Maerz 21 Reputation points
    2020-12-31T12:38:50.297+00:00

    Hi,

    I know what you mean, but my problem is, that there are so many settings in a task list (assigend to, subtasks, duedate, ...) and I don't really know all the field names for them.

    Also I am always getting an error:

    Apply-PnPProvisioningTemplate : Die Spalte 'Description' ist nicht vorhanden. Möglicherweise wurde sie von einem anderen Benutzer gelöscht.

    When I delete the field in my Template:

    <ViewFields>
    <FieldRef Name="StartDate" />
    <FieldRef Name="DueDate" />
    <FieldRef Name="Title" />
    <FieldRef Name="Description" />
    </ViewFields>

    It works pretty good with your fields (:

    It is possible that they will add other custom fields, so it would be really nice, if just all fiels would be added without the need of adding them manually in the fields parameter.

    I really appreciate your help so far!

    Cheers
    Chris


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.