Fix PortalUrl on all Site Collections

Script

Name

Description

Last Modified Date

Download

UpdatePortalUrls.ps1

Fixes the Site Collection PortalUrl for all sites in a web application.

This fixes an issue where "Add to My Links" directs you to a page with an invalid URL.

The forward slash is missing. Eg: https://myintranet_vti_bin/portalapi.aspx?cmd=PinToMyPage...

20/03/2013

None

param ($webappUrl  = (Read-Host "Please enter the web application url"))
$webapp = Get-SPWebApplication $webappUrl
if($webapp -eq $null)
{
	throw "Cannot find web app"
}
$invalidSites = $webapp | get-spsite -Limit all | Where-Object {![string]::IsNullOrEmpty($_.PortalUrl) -and !$_.PortalUrl.Endswith('/') } 
if($invalidSites -eq $null)
{
	Write-Host "No sites found needing update"
	return
}
Write-Host "Invalid sites"
$invalidSites | fl Url, PortalUrl
Write-Host "About to update " $invalidSites.Count " sites"
$yes = Read-Host "Confirm Y"
if($yes -ieq "y")
{
	foreach($site in $invalidSites)
	{
		$site.PortalUrl += "/"
		$site.Dispose()
		Write-Host "Updated " $site.Url
	}
}

CodeMonkey Software is a division of JCHMedia www.jchmedia.com