SOLVED

Invoke-PnPSiteTemplate Changes Page Links

%3CLINGO-SUB%20id%3D%22lingo-sub-2676459%22%20slang%3D%22en-US%22%3ERe%3A%20Invoke-PnPSiteTemplate%20Changes%20Page%20Links%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2676459%22%20slang%3D%22en-US%22%3E%3CP%3EI%20didn't%20notice%20at%20first%20that%20the%20URL%20for%20each%20link%20started%20with%20%22%7Bsite%7D%22.%20After%20the%20export%20command%20executed%2C%20I%20was%20able%20to%20open%20up%20the%20temp%20file%20with%20Notepad%20and%20do%20a%20find-and-replace%2C%20replacing%20%22%7Bsite%7D%22%20with%20the%20full%20URL%20of%20the%20source%20site%20(%3CA%20href%3D%22https%3A%2F%2Fcompany.sharepoint.com%2Fsites%2Fsitename%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fcompany.sharepoint.com%2Fsites%2Fsitename%3C%2FA%3E).%20I%20then%20executed%20the%20second%20command%20to%20create%20the%20page%20on%20the%20destination%20site.%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EIt's%20worth%20noting%20that%20each%20link%20is%20listed%20twice%2C%20the%20first%20is%20the%20actual%20link%20while%20the%20second%20is%20what%20shows%20up%20when%20you%20hover%20over%20the%20link.%3C%2FP%3E%3CPRE%3Ea%20href%3D%26amp%3Bquot%3B%7Bsite%7D%2FSitePages%2Fsitepage.aspx%26amp%3Bquot%3B%20data-cke-saved-href%3D%26amp%3Bquot%3Bhttps%3A%2F%2F%23company%23.sharepoint.com%2Fsites%2F%23site%23%2FSitePages%2Fsitepage.aspx%26amp%3Bquot%3B%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2675786%22%20slang%3D%22en-US%22%3EInvoke-PnPSiteTemplate%20Changes%20Page%20Links%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2675786%22%20slang%3D%22en-US%22%3E%3CP%3ETo%20move%20pages%20from%20one%20site%20to%20another%20(SharePoint%20Online%2C%20modern)%2C%20I%20use%20the%20PnP%20PowerShell%20commands%20below%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3ESource%20site%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EExport-PnPPage%20-Identity%20%24pageName%20-Force%20-Out%20%24tempFile%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EDestination%20Site%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EInvoke-PnPSiteTemplate%20-Path%20%24tempFile%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20problem%20is%2C%20once%20the%20page%20is%20on%20the%20destination%20site%2C%20all%20the%20links%20have%20been%20changed%20so%20they%20point%20to%20the%20destination%20site.%20I%20understand%20that%20this%20is%20typically%20desirable%2C%20but%20in%20this%20case%20I%20need%20to%20them%20to%20stay%20constant.%20Does%20anyone%20know%20of%20a%20way%20to%20do%20this%3F%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EI%20have%20been%20looking%20for%20other%20commands%20to%20maybe%20get%20the%20text%20of%20the%20page%2C%20have%20PowerShell%20find%20and%20replace%20the%20links%20back%20to%20the%20original%2C%20and%20then%20write%20the%20text%20back%2C%20but%20I%20don't%20think%20that's%20possible%20with%20PnP%20PowerShell.%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EAny%20help%20would%20be%20appreciated.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2675786%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

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 (Occasional Contributor)
Solution

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 (https://company.sharepoint.com/sites/sitename). 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="https://#company#.sharepoint.com/sites/#site#/SitePages/sitepage.aspx"