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? 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. Commented Feb 20, 2020 at 10:38

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.