Invoke-PnPSiteTemplate Changes Page Links


To move pages from one site to another (SharePoint Online, modern), I use the PnP PowerShell commands below:

Source site:    


Export-PnPPage -Identity $pageName -Force -Out $tempFile


Destination Site:


Invoke-PnPSiteTemplate -Path $tempFile


The problem is, once the page is on the destination site, all the links have been changed so they point to the destination site. I understand that this is typically desirable, but in this case I need to them to stay constant. Does anyone know of a way to do this?

I have been looking for other commands to maybe get the text of the page, have PowerShell find and replace the links back to the original, and then write the text back, but I don't think that's possible with PnP PowerShell.

Any help would be appreciated.

1 Reply
best response confirmed by Steve Wright (Contributor)

I didn't notice at first that the URL for each link started with "{site}". After the export command executed, I was able to open up the temp file with Notepad and do a find-and-replace, replacing "{site}" with the full URL of the source site ( I then executed the second command to create the page on the destination site.

It's worth noting that each link is listed twice, the first is the actual link while the second is what shows up when you hover over the link.

a href="{site}/SitePages/sitepage.aspx" data-cke-saved-href=""