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()
}
}
Andreas Felder on February 6, 2012 at 20:14 said:
Hey,
Awesome script really saved me!! I just had to fix one minor thing:
$userProfiles = $profileManager.GetEnumerator()
This line should actually be:
$userProfiles = $userprofileManager.GetEnumerator()
As that is the variable created by the previous statement.
Thanks,
Andreas
Norman Bauer on February 6, 2012 at 21:51 said:
Oh thanks. I fixed that one.
Peter on March 28, 2012 at 21:33 said:
Hi,
I’ve just changed the URL of the My Site, and I’m having a bit of issues with this script, since I’m a complete newbie to Powershell.
When trying to run the script I’m getting prompted for TypeName, could you tell me what I’m doing wrong here? Thanks!
Peter on March 29, 2012 at 09:26 said:
Thanks a lot for this script, saved me heaps of trouble!
In regards to the comment above, I was getting some errors due to the fact that I wasn’t running the script as a user with permissions to change the MySite.
Norman Bauer on March 29, 2012 at 09:59 said:
@Peter
You’re welcome… At least I did not mention that you better run this script in a Powershell elevated by a farm administrator. Thanks for the hint on that.
Jonathon McDougall on April 30, 2012 at 21:33 said:
I was having trouble changing my URL from http://portal/my/ to http://portal/ – The script ran fine, but the old and new URLS were the same. I changed this line:
$newPictureUrl = $oldPictureUrl.Replace($mySiteOldUrlValue, $mySiteNewUrlValue)
to
$newPictureUrl = $oldPictureUrl -Replace($mySiteOldUrlValue, $mySiteNewUrlValue)
and everything worked.
Duane Alleman on August 2, 2012 at 17:36 said:
I have run this script and it completes without errors, but I noticed the path for some of the photos is:
oldPictureUrl = https://mysite.companyname.net/user photos/profile picturesUser Photos/Profile Pictures/me_MThumb.jpg –> newPictureUrl = https://mysite.companyname.net/user photos/profile picturesUser Photos/Profile Pictures/me_MThumb.jpg
Any ideas how I can correct the duplicate path? If I manually remove the duplicate user photos/profile pictures (so that there is only 1 in the path) then it displays the picture in the browser.
Any help would be greatly appreciated.
Norman Bauer on August 7, 2012 at 09:42 said:
@Duane Alleman
You could simply edit the script not to replace old vs. new url but replace that “double” url:
Norman Bauer on August 7, 2012 at 09:42 said:
@Jonathon McDougall
Thanks for the hint, I changed that.