I have many Pages in SharePoint Online, with modern text editor having many document links pointing to Document library within same Site Collection. Now we are planning to move documents into multiple document library based on some classification. Hence we want to update the existing URL with new URL. Is there a way to update links without editing each page manually and update?

Here is an example of a page

enter image description here

1 Answer 1


You could possibly have considered using Document IDs so URLs to documents are kept even when moved to another library or site.


However, assuming you haven't done so, you can use PnP.PowerShell to build a script that iterates SharePoint Online site pages.


# define which site collection you want to run the script on
$siteCollectionUrl = ""

# replacement hastable where the key is the old document url and the value is the new document url
$replacementlist = @{"https://olddocumenturl" = "https://newdocumenturl"}

# Connect to SharePoint site
Connect-PnPOnline -Url $siteCollectionUrl -Interactive

# Get list items
$pages = Get-PnPListItem -List "Site Pages" 

# Iterate list items
foreach($page in $pages) {
   # do work

On every page you must iterate the page controls and look for the PageText type, and then some additional logic to replace the actual URLs before saving and re-publishing the page.

Hopefully this is helpful and can get you started.

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.