SharePoint 2010: Import User Profile photos from file system

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:

https://www.tcscblog.com/2010/11/18/import-user-profile-photos-from-active-directory-into-sharepoint-2010/

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:

https://somecomputername/1001.jpg

or may be,

https://somecomputername/photos/1001.jpg

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:

emp_id,domain_user_name

https://somecomputername/1001.jpg,donf

https://somecomputername/1002.jpg,toms

Now create a Powershell script file (PS1) like this:

===============================================================

[void][system.reflection.assembly]::loadwithpartialname("Microsoft.Office.Server.UserProfiles")

$csvFile = "D:\photo.csv"

$MySiteUrl = https://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)

if($up)

{

$up["PictureURL"].Value = $line.emp_id

$up.Commit()

write-host $user_name,"--->",$up.DisplayName,"--->",$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 “https://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 “https://somecomputername/1001.jpg”, just go ahead and change your csv and make the emp_id from “https://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.