We have done a migration from SP2007 to SP2013 but we have got some broken image URLs. I have searched around for a solution but they all are about either top menu or left menu and the publishing pages. These broken images URLs are located in normal pages as well. Is it possible to fix urls that are in normal pages, NOT in publishing pages? Can anyone share some code or some thoughts? Thank you.

  • so you want to change the links in the page content and not just in the quick and top bar?
    – Nk SP
    Apr 19, 2015 at 16:05
  • yes, just in the pages.
    – Imir Hoxha
    Apr 26, 2015 at 7:45

1 Answer 1


Well, everything is stored in web parts like content editor webparts so by using the script below i was able to solve my problem:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get all Webs

$webs = Get-SPWebApplication "http://sharepoint.crescent.com" | Get-SPSite -Limit All | Get-SPWeb -Limit All

#Iterate through webs 
foreach ($web in $webs)
#Get All Pages from site's Root into $AllPages Array

$AllPages = @($web.Files | Where-Object {$_.Name -match ".aspx"}) 
#Search All Folders for Pages
foreach ($folder in $web.Folders)

  if($folder.Name -ne "Forms") #Leave "Forms" Folder
         #Add the pages to $AllPages Array
         $AllPages += @($folder.Files | Where-Object {$_.Name -match ".aspx"})



 #Iterate through all pages

 foreach($Page in $AllPages)

     #Web Part Manager to get all web parts from the file

     $WebPartManager = $web.GetLimitedWebPartManager( $Page.ServerRelativeUrl,  [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
     #Iterate through each web part

     foreach($webPart in $WebPartManager.WebParts)  
        # Get All Content Editor web parts with specific Old Link

        if( ($webPart.Content.InnerText -like '*'+$OldLink+'*' ) -and ($webPart.GetType() -eq [Microsoft.SharePoint.WebPartPages.ContentEditorWebPart]) ) 

     #Get the Old content from CEWPs
     $OldContent =  $webPart.Content
           $OldContentXml = $OldContent.InnerText

           #Replace the Old Links 
     $XmlDoc = New-Object System.Xml.XmlDocument
     $NewContentXml= $XmlDoc.CreateElement("content") 
           $NewContentXml.InnerText= $OldContentXml.Replace($OldLink, $NewLink)

     #Set content and Save
     $webpart.Content = $NewContentXml    
     Write-Host "Replaced a link in $($Page.ServerRelativeUrl))"





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.