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

June 18, 2012 at 4:34 pm | Posted in Administration, Fixes, Functionality, PowerShell | 1 Comment
Tags: , , , ,

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
        $childNode.Update()
       
    }
    $web.Update()
    $web.Dispose()
}
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:

image

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:

http://gallery.technet.microsoft.com/scriptcenter/Update-specified-59552f37

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. 

Advertisements

1 Comment »

RSS feed for comments on this post. TrackBack URI

  1. […] article has been cross posted from pwmather.wordpress.com (original article) Share this:TwitterFacebookLike this:LikeBe the first to like this. This entry was posted in […]


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

Blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: