Import profile pictures from an external application

3 באוקטובר 2011

2 תגובות

I recently came across a familiar situation where I needed to synchronize user profiles inside SharePoint 2010 so they will include the profile picture which is defined elsewhere.

Usually users have their pictures included inside the Active Directory either as an extended schema or as a field which holds the URL where the image can be found. These cases are covered and can be easily solved in various ways. One of them is described here (Hebrew) using FIM or here (English) using simple mappings.

My situation was different – my users images were stored on an external HR application which exposed them via a URL which contained a unique identifier of the user. In my case it was an internal employee ID although it could be email, login name etc.

The URL was something like that: http://ourhrapplication/userimage.aspx?employeeid=12345  where 12345 is that unique identifier.

In our case this field was also replicated inside Active Directory under the property “EmpId”.

MY solution for importing the profile images from the external HR system inside our SharePoint 2010 portal user profiles (and My Site) is based on two steps:

1) Powershell script for setting the PictureUrl property of the user profile with the profile image URL of the external system.

2) A powershell command which will resize the image and store it inside the My Site user profile images library.

 

The script looks something like this:

#Set up default variables

 

 #My Site URL

$mySiteUrl = "http://my.portal.corp/"

 #Unique identifier property name from AD, can be user name, email, employee id etc.

$uniqueIdentifier="EmpId"

 #Image url format with the unique identifier as {0}

$newPictureURL = "http://ourhrapplication/userimage.aspx?employeeid={0}"

 

 

 

#The internal name for PictureURL

$upPictureURLAttribute = "PictureURL"

 

#Get site objects and connect to User Profile Manager service

$site = Get-SPSite $mySiteUrl

$context = Get-SPServiceContext $site

$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

$profiles = $profileManager.GetEnumerator()

 

foreach ($userProfile in $profiles) {

 

f ((-not [System.String]::IsNullOrEmpty($userProfile[$uniqueIdentifier])) -and ([System.String]::IsNullOrEmpty($userProfile[$upPictureURLAttribute])))

{    

   $uniqueIdentifierValue=$userProfile[$uniqueIdentifier] 

   $formatedImageUrl=$newPictureURL -f $uniqueIdentifierValue 

   write-host "Image URL" :  $formatedImageUrl

 

   $userProfile[$upPictureURLAttribute].Value = $newPictureURL

   $userProfile.Commit()

 }

 

}

 

(I was inspired by a similar solution which also describes updating user profile properties via powershell)

 

The second step is to run a powershell command which is already provided by SharePoint:

Update-SPProfilePhotoStore –MySiteHostLocation “http://intranet/my/”

(You should run this command from the SharePoint management shell)

This command will go through all user profiles and update the images thumbnails according to the URL we defined in the previous step.

More on this can be found here: SharePoint 2010, Office 2010 and profile pictures. (This post will also direct you to your next stop – embedding profile pictures in exchange 2010 and Outlook 2010)

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *

2 תגובות

  1. Patrick12 במרץ 2012 ב 14:16

    Excellent, this was exactly what I needed!!
    Thanks a lot for this great script!

    There was a small adjustment needed:
    $uniqueIdentifierValue=$userProfile[$uniqueIdentifier].toString()
    ..
    $userProfile[$upPictureURLAttribute].Value = $formatedImageUrl
    $userProfile.Commit()
    ..

    הגב
  2. bathroomcabinet14 בינואר 2013 ב 6:25

    bathroom cabinet 2012
    Best bathroom cabinet 2012
    types of bathroom cabinet

    הגב