SharePoint 2010: Import User Profile photos from file system

SharePoint 2010: Import User Profile photos from file system

Rate This
  • Comments 5

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:

http://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:

http://somecomputername/1001.jpg

or may be,

http://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

http://somecomputername/1001.jpg,donf

http://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 = 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)

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 “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.

Leave a Comment
  • Please add 3 and 3 and type the answer here:
  • Post
  • This is exactly what i was looking for.. in fact this is the only article i could find for this kind of situation..

    Tried and its sync photos from file-server correctly..

    Only thing i would like to add is the following command,which will create crop photos and store them My Site..

    Update-SPProfilePhotoStore -CreateThumbnailsForImportedPhotos 1 -MySiteHostLocation

    http://<YourServerName>/my

    Great Job !

  • that's clever! although a paid AD sync software may achieve this also, www.sharepointboost.com/active-directory-sync.html. simple but need money

  • very nice information.

  • This is an excellent posting.  Thank you.

    Just one question...

    Looking at the PS code, It seems that I can use this for other attributes in the profile.  Like phone, extension, location, etc...  If I have a csv of all that, I can populate any attribute in the profile, right?

    Thanks

    Ron

  • Hello Parnab,

    Thank you for this Post helped me a lot, only a short question...

    Is is also possible to import the User Profile Pics from a normal FileSystem without creating a site?

    So in my Case, we have a Folder with our Pics and would like to synch them to the User Profiles without creating a site...is this possible? all PS Scripts i found, needed a Site.

    Thanks a lot, greets

    Smartie

Page 1 of 1 (5 items)