Code Solution – Import AD Photos into SharePoint User Profiles

[Update: Code download files updated 18/03/2011 – see below]

This is in relation to a previous post I made last week;

Active Directory Images are not imported by the SP2010 User Profile Import

So, the source code is finally ready and uploaded for your enjoyment 🙂

Now – I must first off give credit to the sources of inspiration. A lot of the code in this solution is copied / borrowed / inspired by the following posts:

All I have done is brought their code and samples together and packaged it into a WSP that runs from SharePoint Timer jobs, so you have the convenience of a SharePoint 2010 farm solution 🙂

Also it should be understood that both AD and the User Profile database are quite critical parts of anyone’s SharePoint farm, so sorry, but first I need to make a ….

… Disclaimer – All code and solutions are provided “as is” and should be used at your own risk! It is highly recommended that you test these in an isolated environment, and I confer no responsibility for any loss or damage from using the code, advice or solutions provided on this blog, or any related content.

Ok, now that is out of the way we can get on with business 🙂

[Update – 18/03/2011 – I have updated both sets of files so that it now uses the “distinguishedName” attribute to identify users in AD .. as this is a more reliable method and was in response to a reported bug]

I have uploaded the files to my Sky Drive including:

When you roll out the WSP you will find that it includes the following functionality:

Farm Scoped Feature
The WSP package includes a farm scoped feature called:

Hatch Solutions – Import Photos from AD (Timer Job)

When activated this will automatically identify the default MySite host application and create a custom Timer Job (see below) attached to that web application.

My Site Timer Job
The Timer Job (installed by the Farm Feature) is designed to run on the My Site Host web application, and is pre-configured to run once-per hour. It is called:

Hatch Solutions – Import Photos from AD

This will do the following:

  • Automatically identify all AD accounts in the current User Profile Database
  • If the AD account has a “jpegPhoto” attribute, then this is extracted
  • The photo is converted to three thumbnail images, and uploaded to the My Site Host profile photo asset library
  • The photo for that user profile is updated to point at their newly uploaded photo

Hope you enjoy, the source code is there for all to see, and good luck!

  • Jonathan

    Is there anyway to use a different AD attribute other than jpegPhoto. Our AD setup uses the thumbnailPhoto attribute.

  • Anonymous

    I installed this and got a 6398 event log entry when the job failed. Any idea why?

  • Anonymous

    Hi Martin,

    Because of server issues, I just installed your latest package yesterday. It works perfectly. Looks like the duplicate photos problem is fixed. The photos are unique and match the ones in AD now.
    Thank you very much for your great work! It really helped us to resolve this photo import problem.

    Thank you!

  • Martin Hatch

    Anon .. yeh sorry about that.

    I have modified the code to use the distinguisedName property to identify user accounts (as this will be unique within AD) so this should solve your problem.

    I will try and get the updated code uploaded this week, and will post an update to this blog when I do so.

    Also, if you email me ( I will let you know when this is online!

  • Anonymous

    We downloaded and installed the tool in our SharePoint 2010 farm. It successfully imported all photos, except with one critical bug: it displays the same photo for all the users that share the same last name. For example, when importing photos from AD for two users that have the same last name, but different account names, for example, A White (account name whitea) and M White (account name white), the tool will import only A White's photo, so A White and M White have the same photo (A White's photo) in SharePoint.

    Hope the developer of this tool can fix this bug. Overall it is a good tool. Easy to use.

  • Martin Hatch

    Dave …

    Sorry, the code that works with the User Profile "Service Application" bit wouldn't work with MOSS 2007 .. although a lot of the core-code would be compatible.

    Give the source code to a MOSS 2007 developer and I'm sure they could get it working.

  • Dave Lee

    Hi Martin

    We allow users to update their contact info and photos in AD via a web applicaton. This works well for Exchange and Lync but not MOSS. You're solution seems to solve the issue except that we are storing pics in the thumbnailPhoto attribute and are running MOSS 2007. Would this SP2010 version run on MOSS?