Tuesday, May 31, 2016

Upgrade MySite to SharePoint 2013 but the photos are not linking back

So I didn't want to follow the Microsoft recommended directions to upgrade mysite for upgrading the service applications for Metadata and the user profile service.   Which  was fine for the metadata service since they weren't using anything on it.   But the user profile service does present one issue, the photo, which is stored in the user profiles.  


But I do have all the pictures on the mysite since it is stored at the root web under the User Photos library.  


here is the script to update the user photos with powershell,   replace the TODO with your information:




[Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
$siteurl = "TODO fill in mysite url"
$site = New-Object Microsoft.SharePoint.SPSite($siteurl)
$context = [Microsoft.Office.Server.ServerContext]::GetContext($site)
write-host $site.RootWeb.Lists["User Photos"]
#Get list of photos
$list = $site.RootWeb.Lists["User Photos"]
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
Write-host $list.Items.Count
foreach($listitem in $list.Items)
{
    if($listitem["Name"].ToString().Contains("LThumb") )
    {
      #  Write-host $listitem["Name"].ToString()
        $user = $listitem["Name"].ToString().Replace("_", "\").Substring(0, $listitem["Name"].ToString().LastIndexOf("_"))
    #    write-host $user
        $fullphotourl = $siteurl + "User%20Photos/Profile%20Pictures/" + $listitem["Name"].ToString();
        write-host $fullphotourl
        if ($upm.UserExists($user))
        {
            $profile = $upm.GetUserProfile($user)
            $profile["PictureURL"].Value = $fullphotourl;
            $profile.Commit();
        }
   
    }
}
$site.Dispose()

No comments:

Post a Comment