I do not normally create blog posts around topics which are covered on other blogs on the Internet however this topic seems to still draw a bit of confusion as well as I wanted to offer a very complete picture (pun totally intended) of how to move user pictures from Active Directory into SharePoint User Profiles.
For this walkthrough I am using a SharePoint 2010 Farm running the April 2011 CU and a single domain controller on Windows 2008 R2.
DNS Domain: sp.com
My Site Host: http://my
I have a number of demo users I have created within Active Directory and I have imported pictures/photos for each user via PowerShell. The PowerShell snip below takes a path to a jpg file ($fileName), reads the file into a byte array, and puts the data into the thumbnailPhoto attribute of a user.
$temp = get-content -encoding byte $fileName $photo = [byte]$temp $newUser.put("thumbnailPhoto", $photo) $newuser.SetInfo()
Once the photo has been set for the user we can use ADSI Edit to confirm as much:
At this point we are ready to configure SharePoint 2010. From the User Profile administration pages select Manage User Properties and choose the edit the Picture property. Scroll to the bottom of this page and choose or ensure the Source Data Connection is the connection to your Active Directory. If you don’t have anything in this drop down list it means you have not configured User Profile Synchronization. I suggest you stop right here and jump on over to Spence’s blog post on the topic. For the attribute choose thunbnailPhoto and direction should be Import. At this point please do yourself a favor and hit the Add button. A common mistake is to skip over the add button and hit the OK button however you are going to be disappointed with the results because that effectively does nothing for you and makes no changes to the property mapping.
Before we move on lets confirm the mapping is in place.From the properties list we should see the picture property with a mapped attribute of thumbnailPhoto as in the image below.
Jumping back into the properties of the Picture attribute we should see the mapping here too. If we have these settings in place we are good to move on.
With the User Properties configured property its time to start a full profile sync. Its important this is a full sync and not an incremental. It’s a good bet the profile sync is going to take a fair amount of time.
Once the full profile sync is complete we need to run a bit of PowerShell which will migrate the user pictures from the User Profile store to a location where they can be accessed via a URL and used within SharePoint. This PowerShell was added to the product in the October 2010 CU and the command is documented here. The command is super simple to run and the PowerShell snip below shows you what this looks like for my environment.
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ### CreateThumbnailsForImportedPhotos added in Oct 2010 CU #### Update-SPProfilePhotoStore -MySiteHostLocation http://my -CreateThumbnailsForImportedPhotos $true ####
There are a couple of things you need to be aware of before you attempt to run this command:
- The user running this command will need permissions to execute PowerShell against the User Profile Manager. To ensure this is the case open Central Admin, navigate to Manage Service Applications, highlight the User Profile Synchronization Service Service Application and choose Permissions. Note I did not mention Administrators but rather Permissions. From inside the Permissions dialog add the user which whom you will use to run the PowerShell script. If you don’t do this you will receive an error such as: Update-SPProfilePhotoStore : Object reference not set to an instance of an object and as they say in Texas, that dog won’t hunt.
- This command walks through your entire User Profile store pulling out each image for every user and creates a large, medium and small thumbnail and uploads those images into the User Photos picture library at the root Site Collection of your My Site Host. So for 30,000 users you will end up with about 90,000 images in this library. The PowerShell command will pause or block until this is complete so just plan for this to take a while.
Once you have finished running the CreateThumbnailsForImportedPhotos command (or while waiting for it to complete), you can open the My Site Host, choose View All Site Content, and verify the number of items in the User Photos picture library.
That’s it, you are done; you have just successfully migrated pictures from Active Directory into the SharePoint User Profile store, and then finally into the My Site host for your farm.