Step by Step: How to Manage the My Site User Profile Pictures in SharePoint 2010

Written by Denis Stadler on . Posted in My Site

The business requirement is quite simple: find a solution for SharePoint My Sites’ pictures.

After the implementation of the User Profile Service (a very good UPS deployment guide can be read on www.harbar.net), and adding data into the following fields in the Active Directory user’s profile:

  • General Tab: First Name, Last Name, Office, Telephone, E-mail
  • Organization Tab: Job Title, Department, Company, Manager

I was able to have all the My Site features up and running (displaying information about users, colleagues, organization hierarchy, search visibility– including skills).

But the big challenge remained: how to add the pictures in a standard way? The solution: the “thumbnailPhoto” field in the Active Directory profile.

The picture thumbnail can be uploaded directly into the Active Directory database, into the “thumbnailPhoto” field if we use a PowerShell script. For SharePoint 2010 the thumbnails need to be 144px * 144px (the SharePoint system will generate 3 thumbnail photos, for each user: 144*144, 96*96, 32*32).

The other limitation is brought up by the Exchange 2010 system: the picture size has to be maximum 10KB. More details about Exchange you can find in this article – GAL Photos in Exchange 2010 and Outlook 2010.

The first step is to import the pictures in Active Directory. What I did was to store all the thumbnail pictures in a folder and then I ran the following commands, using the AddUserPhotoAD.ps1 PowerShell script:

set-executionpolicy remotesigned

# Run it for each user
# The script takes two parameters
.\AddUserPhotoAD.ps1 "user.logon.name" "user.logon.name.jpg"

PowerShell: Add User’s photo to Active Directory

Write-Host "Num Args:" $args.Length;
foreach ($arg in $args)
{
  Write-Host "Arg: $arg";
}

$username = $args[0]
$jpgfile = $args[1]

# Write-Host "$username";
# Write-Host "$jpgfile";

$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$root = $dom.GetDirectoryEntry()
$search = [System.DirectoryServices.DirectorySearcher]$root
$search.Filter = "(&(objectCategory=User)(samAccountName=$username))"
$result = $search.FindOne()

if ($result -ne $null)
{
 $user = $result.GetDirectoryEntry()
 [byte[]]$jpg = Get-Content $jpgfile -encoding byte
 $user.put("thumbnailPhoto",  $jpg )
 $user.setinfo()
 Write-Host $user.displayname " has been updated."
}
else
{
Write-Host $struser "doesn't exist in the domain."
}

The second step is grant permissions to the account you use for logging into the SharePoint server. Open the Central Administration web site and navigate to Manage service applications page (Application Management > Manage service applications).

Click on the User profile service entrance, but not on the name, and then on the Permissions button in the Ribbon.

Add your user and check the “Full Control” check. Then from the Services application page click on the Administration button.

Add your user and check only the “Manage Profiles” check.

Then it’s time to create an import “PictureURL” mapping in the User Profile. Open the User profile service administration page, and click on the Manage User Properties link.

Search for the Picture attribute (it is located under the Basic Information) and edit it.

Add the “thumbnailPhoto” as a new mapping and click ok, and then start a full profile import.


After the import is finished, open a SharePoint 2010 Management Shell and run the following command:

# Replace the MySiteHostLocation value
Update-SPProfilePhotoStore -CreateThumbnailsForImportedPhotos 1 -MySiteHostLocation "http://mysite.stadler.local"

Now you should have imported all the pictures inside SharePoint.

Tags: , ,

Trackback from your site.

Denis Stadler

I'm a technology enthusiast, with more than 10 years of experience in SharePoint and Dynamics CRM projects. To find more details about, please visit the about me page.

Leave a comment

*