Update #SharePoint absolute URLs with relative URLs using #PowerShell #ProjectServer #PS2010 #SP2010

I recently came across an issue with a document library URL on the project sites after the client rolled over the Production environment to the Test farm. When the Project site template was created, a link to a central document library on another site collection was added to the quick launch. The absolute URL was used rather than the relative URL, subsequently all project sites created from that template have the full URL. This obviously works fine for the Production environment but when the project sites are migrated to the Test environment with the environment rollover, the links for this document library point to the Production environment.

Rather than going to each project site and updating the URL manually to the relative URL or asking one of our developers to create a console app to do this, I thought I’d try with PowerShell.

Below is the PowerShell script:

# Script will update the absolute Url on the quick launch link under the specified heading
# with the relativeUrl

# add SharePoint snapin
Add-PSSnapin Microsoft.SharePoint.PowerShell –ea SilentlyContinue
#set variables
$site = "http://vm353/PWA"
$QuickLaunchHeading = "Libraries"
$absoluteUrl = "http://vm353/Shared documents"
$relativeUrl = "/Shared Documents"
foreach ($web in (Get-SPSite  $site | Get-SPWeb -Limit All))
    $node = $web.Navigation.QuickLaunch | where { $_.Title -eq $QuickLaunchHeading }

    foreach($childNode in $node.Children | where { $_.URL -eq ($absoluteUrl) })
        Write-host "Updating" $childNode.Title "on the following site" $web.Url
        $childNode.URL = $relativeUrl
Write-host "Finished!" -foregroundcolor "Green"

The script above requires four variables to be updated for your environment:

$site = "http://vm353/PWA"           – The site collection URL where the Project Sites exist
$QuickLaunchHeading = "Libraries"  – The quick launch heading where the link exists
$absoluteUrl = “http://vm353/shared documents”   – The URL for the link that needs updating
$relativeUrl = "/Shared Documents"  – The correct relative URL for the link

As you can see in this example for my testing, my project sites have a link under the Libraries heading to the root site’s shared documents. The script will show what links have been updated as shown below:


Whilst the example above is showing document library links, this script will update any quick launch links providing the correct heading and absolute URL variables are set. The script will also work for non PWA site collections.

The script is available for download from the script gallery, link below:


As always, this script is provided as is with no warranties etc. use at your own risk and test on a test environment before using on a production environment. 

One thought on “Update #SharePoint absolute URLs with relative URLs using #PowerShell #ProjectServer #PS2010 #SP2010

Comments are closed.

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: