Update all quick launch links via PowerShell

As part of the process of upgrading SharePoint or perhaps simply moving web applications to a different URL, sometimes it is necessary to update multiple quick launch links that point to an old URL so they now resolve to a new URL.

These could be links to the ‘old’ SharePoint URL that have been manually created or links to an external system that has had a URL change. Either way, the script below will scan through the entire site and update any links that contain either of the ‘from’ URLs.

NB: SharePoint does a great job of updating ‘internal’ links but this does not stop users creating fully qualified links that contain an old URL nor can SharePoint automatically update links to external URLs

Add-PSSnapin Microsoft.SharePoint.PowerShell –erroraction SilentlyContinue

## urls to search for
$fromURL = "
$fromURL2 = "http://from.another.url"

## the url to be used as a replacement
$toURL = "http://bc01"

foreach ($web in (Get-SPWebApplication $toURL | Get-SPSite -Limit All | Get-SPWeb -Limit All))
    ## scan the web quick launch urls
    Write-Host "Scanning " $web.Url

    $nodes = $web.Navigation.QuickLaunch
    foreach ($node in $nodes)
        $nodeUrl = $node.Url
        if ($nodeUrl.ToString().ToLower().Contains($fromURL) -or $nodeUrl.ToString().ToLower().Contains($fromURL2))
            Write-Host "     found link to: " -foreground gray -nonewline; Write-Host $nodeUrl -nonewline
            ## update the link
            $nodeUrl = $nodeUrl.ToString().ToLower().Replace($fromUrl,$toURL).Replace($fromUrl2,$toURL)
            $node.Url = $nodeUrl
            Write-Host " – done." -foreground green


I hope this helps


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: