Find and Replace Old Link URLs in Quick Launch, Top Navigation Menus during Migration

Found so many hard-coded links (Absolute links) in SharePoint Quick launch and in Top navigation bar. This PowerShell script, Scans and Replaces the provided Old URL with the New URL all over the SharePoint web Application.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set Old & New URLs
$OldURL = "https://moss2007.crescent.com"
$NewURL = "https://sharepoint2010.crescent.com"

#Get all sites of the web application
$webs = Get-SPWebApplication "https://sharepoint.crescent.com" | Get-SPSite -Limit All | Get-SPWeb -Limit All
 
#Iterate through webs
ForEach ($web in $webs)
{
    #Get the Quick Launch Bar Nodes
    $QuickLaunchNodes = $Web.Navigation.QuickLaunch 
    #For Top Navigation use: $Web.Navigation.TopNavigationBar . TOp Nav may or May not have child nodes

    #Iterate through each Parent nodes of Quick launch
    Foreach ($parentNode in $QuickLaunchNodes)
    { 
        If($parentNode.Url -match $OldURL)  #if you want to match Link text, use: $parentNode.Title
        {
            $parentNode.Url = $parentNode.Url.Replace($OldURL,$NewURL)
            $parentNode.Update()
            Write-Host "$OldURL Updated!"
        }
        #Get the Child Nodes
        $childNodes = $parentNode.Children
 
        #Iterate through child nodes
        Foreach ($childNode in $childNodes)
        {
            If($childNode.Url -match $OldURL)
            {
                $childNode.Url = $childNode.Url.Replace($OldURL,$NewURL)
                $childNode.Update()
                Write-Host "$OldURL Updated!"
            }
        }
    }
}
 

This script may even helpful when you move your SharePoint web application to different URL.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

5 thoughts on “Find and Replace Old Link URLs in Quick Launch, Top Navigation Menus during Migration

  • Hi I know this is a old article but was wondering if you have a similar script to do the same on MOSS 2007. I have an old MOSS 2007 site that i have moved to a new server that will remain MOSS 2007 as an archive but now need to update all the quick launch items as some are hard coded. My issue is that MOSS 2007 doesnt allow for the PSSnapin If you could show me an example it would be hugely appreciated.

    Reply
    • Thanks for the quick reply, i have tried as you mention to use the above and creating a seperate PS script for the functions so one for get site, one for get web applicaton and one for spweb i have created them with the functions as shown in the link you included. Then i have included them in my new fixupurl script but it doesent work here is the fix up script
      . “D:PSgetSPWebApplications.ps1”
      . “D:PSgetSPWeb.ps1”
      . “D:PSgetSPSite.ps1”

      #Set Old & New URLs
      $OldURL = “https://myoldSite”
      $NewURL = “/”

      #Get all sites of the web application
      $webs = Get-SPWebApplication “https://mynewsite” | Get-SPSite -Limit All | Get-SPWeb -Limit All

      #Iterate through webs
      foreach ($web in $webs)
      {
      #Get the Quick Launch Bar Nodes
      $QuickLaunchNodes = $Web.Navigation.QuickLaunch
      #For Top Navigation use: $Web.Navigation.TopNavigationBar . TOp Nav may or May not have child nodes

      #Iterate through each Parent nodes of Quick launch
      foreach ($parentNode in $QuickLaunchNodes)
      {
      if($parentNode.Url -match $OldURL) #if you want to match Link text, use: $parentNode.Title
      {
      $parentNode.Url = $parentNode.Url.Replace($OldURL,$NewURL)
      $parentNode.Update()
      Write-Host “$OldURL Updated!”
      }
      #Get the Child Nodes
      $childNodes = $parentNode.Children

      #Iterate through child nodes
      foreach ($childNode in $childNodes)
      {
      if($childNode.Url -match $OldURL)
      {
      $childNode.Url = $childNode.Url.Replace($OldURL,$NewURL)
      $childNode.Update()
      Write-Host “$OldURL Updated!”
      }
      }
      }
      }
      $Web.Dispose()

      but it keeps throwning the error

      New-Object : Constructor not found. Cannot find an appropriate constructor for type Microsoft.SharePoint.SPSite.
      At D:PSgetSPSite.ps1:6 char:22
      + return new-Object <<<< Microsoft.SharePoint.SPSite($url) + CategoryInfo : ObjectNotFound: (:) [New-Object], PSArgumentException + FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand The term 'Get-SPWebApplication' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At D:PSfixUpURLS.ps1:10 char:29 + $webs = Get-SPWebApplication <<<< "https://inttest.capitasymonds.co.uk" | Get-SPSite -Limit All | Get-SPWeb -Limit All + CategoryInfo : ObjectNotFound: (Get-SPWebApplication:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException You cannot call a method on a null-valued expression. At D:PSfixUpURLS.ps1:43 char:13 + $Web.Dispose <<<< () + CategoryInfo : InvalidOperation: (Dispose:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Any Ideas where im going wrong ?

      Reply
    • Any way to show where it made the changes? vs. just outputting oldurl Updated!

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *