So, you have successfully deployed User Profile Service and Mysite with SharePoint 2010. Now, the question is how to populate the users’ profile photo. The general expectation around SharePoint 2010 is each user will upload their individual profile photo. Lot of people may disagree, reason - well, a user can upload their pet’s photo or favorite holiday location’s photo or God knows what.
Your CTO may not approve it. Hence, the second choice, Import User Profile Photos from Active Directory. Here is a good article about it:
Wait a little. You got shocking news from the Server Admin team. They do not keep thumbnails (user’s photo) in AD. Instead of that, all the users’ photos (snaps taken during assigning them with an access/identity card) are dumped into a file server. And the references are available in some obscure database.
What to do now? Don’t worry we have a solution. Let’s discuss it:
Let’s say the DB maintains at least 3 fields:
EMP ID User Name Photo Name
1001 donf 1001.jpg
1002 tomg 1002.jpg
First of all create an IIS site and copy all the photos within the root file location of the site so that you can browse the photos like:
or may be,
Just to avoid conflict give read permission to all users to the physical folder where the photo images are located.
Let’s create a csv file out of the DB. The structure of the csv file goes like:
Now create a Powershell script file (PS1) like this:
$csvFile = "D:\photo.csv"
$MySiteUrl = http://mysite.contoso.com/
$site = Get-SPSite $MySiteUrl
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$csv = import-csv -path $csvFile
foreach ($line in $csv)
$user_name = "contoso\" + $line.domain_user_name
$up = $profileManager.GetUserProfile($user_name)
$up["PictureURL"].Value = $line.emp_id
$up = $null
Run the PS1 file from Powershell.
Now if you go to each user’s profile you can see the images are available but if you hover you can see it’s coming from the location “http://somecomputername/1001.jpg”.
Next step is, give SharePoint a free hand to resize those photos into 3 different sizes. Run this command in Powershell window:
Update-SPProfilePhotoStore -MySiteHostLocation https://mysite.contoso.com/
Now most of the photos must got copied into User profile DB. If you still see the photo url’s pointing to “http://somecomputername/1001.jpg”, just go ahead and change your csv and make the emp_id from “http://somecomputername/1001.jpg” to the URL where Mysite is storing the photos (just check with any photo which pointing to mysite correctly).
Run the PS1 a few times and “Update-SPProfilePhotoStore -MySiteHostLocation https://mysite.contoso.com/” as well.
This should do the job.
But also update your CTO, this is a temporary solution and saving thumbnail in AD is a better solution any day.