Not all data copies across between SharePoint Sites using PowerShell

Anonymous
2022-10-20T11:14:47.09+00:00

Hello SharePoint Community,

MS have referred me to this site for help.

I have recently been getting to grips with PowerShell as a means to copy data (Pages, Files and Themes) between SharePoint Sites. The Home page on the source site has 6 Call to Actions, plus a banner and news post. All but one of the call to actions, the Theme and banner copied across to the new site (created initially as a blank). I place 2 screenshots below of the source and destination home pages.

The source home page looks like this:

252408-sharepoint1.jpg

The destination home page is this...

https://learn.microsoft.com/en-us/answers/storage/attachments/236485-sharepoint-destination.jpg

Any further guidance would be greatly appreciated in customising the PowerShell code to reproduce the data and look and feel to the destination site.

A link to the full thread where you can see the code I used is below.

https://learn.microsoft.com/en-us/answers/questions/988546/not-all-data-copies-across-between-sharepoint-site.html

Thanks

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

3 answers

Sort by: Most helpful
  1. Tong Zhang_MSFT 9,141 Reputation points
    2022-10-21T05:28:43.533+00:00

    Hi @Anonymous ,

    According to my research and testing, you can use the following PowerShell code to copy sites page :

    try {    
        $srcUrl = "https://xxxx.sharepoint.com/sites/xxx"    
        $destUrl =  "https://xxxx.sharepoint.com/sites/ComTest"    
        $pageName =  "test-site.aspx"    
          
        Connect-PnPOnline -Url $srcUrl -Credentials $cred  
        $tempFile = [System.IO.Path]::GetTempFileName();    
        Export-PnPClientSidePage -Force -Identity $pageName -Out $tempFile    
        Connect-PnPOnline -Url $destUrl -Credentials $cred    
        Apply-PnPProvisioningTemplate -Path $tempFile    
        Write -Host "ModernPage is successfully copied."    
        sleep 10    
    } catch {    
        Write -Host -ForegroundColor Red 'Error ', ':'    
        $Error[0].ToString();    
        sleep 10    
    }    
    

    My test result:

    252834-image.png

    More information for reference:
    Copy Sites Page From One Site To Another Using PNP PowerShell
    How to Copy a Site in SharePoint Online using PowerShell?

    Hope it can help you. Thanks for your understanding.

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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

  2. Anonymous
    2022-10-21T11:29:06.21+00:00

    Thanks for the code sample. I adjusted it to my site requirements, but it ran into an unexpected token error. Any ideas why?

    PS C:\Users\xxxx> {
    $srcUrl = "https://xxxx.sharepoint.com/sites/TestCommunicationsSite"
    $destUrl = "https://xxxx.sharepoint.com/sites/ComTest"
    $pageName = "test-site.aspx"

     Connect-PnPOnline -Url $srcUrl -Credentials $cred  
     $tempFile = [System.IO.Path]::GetTempFileName();    
     Export-PnPClientSidePage -Force -Identity $pageName -Out $tempFile    
     Connect-PnPOnline -Url $destUrl -Credentials $cred    
     Apply-PnPProvisioningTemplate -Path $tempFile    
     Write -Host "ModernPage is successfully copied."    
     sleep 10    
    

    } catch {
    Write -Host -ForegroundColor Red 'Error ', ':'
    $Error[0].ToString();
    sleep 10
    }

    At line:13 char:4

    • } catch {
    • ~~~~~
      Unexpected token 'catch' in expression or statement.
    • CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
    • FullyQualifiedErrorId : UnexpectedToken

    PS C:\Users\xxxx>


  3. Anonymous
    2022-10-26T10:30:53.833+00:00

    Hi @Tong Zhang_MSFT ,

    I ran your code again with "Try" (not sure what that does) and at least the commands attempted to connect me. However, it now wants me to use 2FA because of my location. I have looked for workarounds and found in one example I'm supposed to download a special PowerShell Module from the Exchange Online. It looks quite a tortuous route just to get connected. Is this the way to proceed or are you aware of a more direct approach?

    Thanks
    David

    0 comments No comments