Tuesday, October 16, 2012

How to fix broken images after mySite URL change in SharePoint 2010?

Reposted from Google Cache – original site failed load

Posted on January 27, 2012 By Norman Bauer

10 Comments

Here is a small PowerShell script to fix the pictureurl for all userprofiles after changing the mySite Url:

$mySiteWebapplicationUrl = "https://mysite.normanbauer.com/"
#current Url of your mySite website

$mySiteOldUrlValue = "http://mysitetest:80/"
#former Url where your pictures do not reside any more

$mySiteNewUrlValue = "https://mysite.normanbauer.com:443/"
#current Url where your images can be found now

$mySite = Get-SPSite $mySiteWebapplicationUrl
$SPServiceContext = Get-SPServiceContext $mySite
$userProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($SPServiceContext)
$userProfiles = $userProfileManager.GetEnumerator()

foreach ($userProfile in $userProfiles)
{
#if pictureurl is not empty replace the old url part with the new one
if ($userProfile["PictureURL"] -ne '')
{
$oldPictureUrl = $userProfile["PictureURL"].toString()
$newPictureUrl = $oldPictureUrl -Replace $mySiteOldUrlValue, $mySiteNewUrlValue
write-host "oldPictureUrl = " $oldPictureUrl " --> newPictureUrl = " $newPictureUrl
$userProfile["PictureURL"].Value = $newPictureUrl
$userProfile.Commit()
}
}

No comments:

Post a Comment