1

I need to get a specific file in the SitePages of a SharePoint Online site collection. I know how to get all pages with PnP (see code below), but I need only one specific.

Export & Import of all sites:

Connect-PnPOnline -url https://contoso.sharepoint.com
Get-PnPProvisioningTemplate -out template.xml -Handlers PageContents -IncludeAllClientSidePages
Connect-PnPOnline -url https://contoso.sharepoint.com/sites/anothersite
Apply-PnPProvisioningTemplate -path template.xml

I checked the .xml in Visual Studio and found elements like "PageName" and "Title" but I can't get it to work. Any ideas? I don't want to edit the complete export in Visual Studio and use that. I has to be easier right?

1
  • Did you mean to get a specific Site Page? Commented Feb 20, 2020 at 8:19

1 Answer 1

2

To download a specific file, use the following syntax:

Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/somesite
Get-PnPFile -Url "/sites/somesite/SitePages/Home.aspx" -AsFile

The parameter -AsFile makes the command save the file to your current directory.

To upload the same file to another site collection, you would use the following:

Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/anothersite
Add-PnPFile -Path .\Home.aspx -Folder SitePages
3
  • Okay, I got that. Can you help me how to add this then to a new site collection?
    – Patrick
    Commented Feb 20, 2020 at 10:26
  • I updated my answer to include upload Commented Feb 20, 2020 at 10:34
  • 1
    Thank you! I knew, it isn't that difficult.
    – Patrick
    Commented Feb 20, 2020 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.