question

VitorVerdura-2385 avatar image
0 Votes"
VitorVerdura-2385 asked ·

Error on copy a page from one sharepoint site to another

Hi all,

I work at a school and have a script to create sites, users and folders automatically. In the finaI steps of the script I need to copy a page from a Sharepoint to another and make it the homepage, but I can't and have been stuck...

Here's what I have so far...


 $cred = Get-Credential
 Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/sitewiththepagemodel -Credentials  $cred
    
 $tempFile = [System.IO.Path]::GetTempFileName();
        
 Export-PnPPage -Identity "SitePages/Bem-vindo-ao-site-da-Turma.aspx" -Force -Out $tempFile
    
 Connect-PnPOnline -Url "https://tenant.sharepoint.com/sites/sitebeingcreated" -Credentials  $cred
 Apply-PnPProvisioningTemplate -Path $tempFile
    
 Set-PnPHomePage -RootFolderRelativeUrl SitePages/Bem-vindo-ao-site-da-Turma.aspx



When run I get the error:


 Export-PnPPage : The object reference was not defined as an instance of an object
 At line:630 char:1
 + Export-PnPPage -Identity "SitePages/Bem-vindo-ao-site-da-Turma.aspx"  ...
 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : NotSpecified: (:) [Export-PnPPage], NullReferenceException
     + FullyQualifiedErrorId : System.NullReferenceException,PnP.PowerShell.Commands.Provisioning.Tenant.ExportPage


  • The part of the error above has been translated

I'm not very good at Powershell so please, be gentle!! ;)

Thanks a lot for your help


office-sharepoint-onlinewindows-server-powershell
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @VitorVerdura-2385,

As this is a public community, in order to protect your personal privacy, I remove the tenant name in your post.

Your issue is related to SharePoint Online, I modify the tag to "office-sharepoint-online".

Thank you for your support and understanding.

0 Votes 0 ·
LiZhang-MSFT avatar image
0 Votes"
LiZhang-MSFT answered ·

Hi @VitorVerdura-2385,

The issue is caused by "SitePages/Bem-vindo-ao-site-da-Turma.aspx".

Quote from Microsoft, the correct syntax should be:

 Export-PnPPage -Identity Home.aspx

Please remove SitePages/ like following:

 Export-PnPPage -Identity Bem-vindo-ao-site-da-Turma.aspx -Force -Out $tempFile

For more information, please refer to:

https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/export-pnppage?view=sharepoint-ps


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.

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

VitorVerdura-2385 avatar image
0 Votes"
VitorVerdura-2385 answered ·

Thaks for you answer.

I already had try that but the error is the same! It's not the solution...

· 3 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @VitorVerdura-2385,

Please provide screenshot of the Export-PnPPage Powershell and Error message.

0 Votes 0 ·

Thanks for your help. Here it is!

71563-1.png


0 Votes 0 ·
1.png (38.7 KiB)

Hi @VitorVerdura-2385,

There is no error on my side, please change another page with simple name to test(ensure the correctness of the page name).

0 Votes 0 ·