Thursday, January 3, 2013

Import User Pictures from Active Directory to SharePoint 2010 My Site

My Organization decided to use Active Directory as a central repository for user profile photos to share with Lync 2010, Outlook and of course SharePoint!

Lets keep other products aside and talk about How to Import User Pictures from Active Directory to SharePoint 2010 My Site. Here is the default My site Profile page without Profile photo imported from AD:

import user pictures from active directory to sharepoint 2010

Well, this article addresses import user pictures from active directory to SharePoint 2010 step by step:
  1. Import user photo into Active Directory user profile's "thumbnailPhoto" attribute.
  2. Configure Property mapping between SharePoint and Active Directory and Run FULL Profile Import.
  3. Run Update-SPProfilePhotoStore cmdlet to generate thumbnails for SharePoint user profile picture.
Assuming UPS is in place, My Site is up and running, SharePoint 2010 SP1 is installed (or October 2010 Cumulative Update), Lets get into details.

Step 1: Import user photo into Active Directory user profile's "thumbnailPhoto" attribute.
If profile pictures are not already in Active Directory user profile's "thumbnailPhoto" attribute, We can import pictures into it. For SharePoint 2010 to import user photo from ad, it must have this attribute populated.
import photo from ad sharepoint 2010

Yes, there are 3rd party tools like AD Photo Edit to import user profile thumbnail photos in bulk,  PowerShell can do it well with just three lines!
Import-Module ActiveDirectory

$photo=[byte[]](Get-Content .\salaudeen_photo.jpg -Encoding byte)

Set-ADUser "Salaudeen" -Replace @{thumbnailPhoto=$photo}

PowerShell Script to Bulk Import User Profile Photos into AD:
Lets say, we've lot of users in AD and their user name, Profile Photo file names are stored in a CSV file with columns "UserName", "PhotoFileName". We can utilize PowerShell to import photo to AD in bulk.

#Read the CSV file - Map the Columns to Named Header (CSV File doesn't has Column Header)
$CSVData = Import-CSV -path "C:\Scripts\UpdateProfilePhoto\UserPhotos.csv" -Header("UserName", "PhotoFileName")

 #Iterate through each Row in the CSV
 foreach ($row in $CSVData)
        #Get the User Name & Photos from CSV file
        $userName= $row.UserName
        $PhotoFile = Join-path "C:\Scripts\UpdateProfilePhoto" $row.PhotoFileName
        #Get the User from AD
        $domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
        $root = $domain.GetDirectoryEntry()
        $search = [System.DirectoryServices.DirectorySearcher]$root
        $search.Filter = "(&(objectCategory=User)(samAccountName=$userName))"
        $result = $search.FindOne()
        if ($result -ne $null)
            #Get the User Object
            $user = $result.GetDirectoryEntry()
            #Get the Photo from Disk
            $photo=[byte[]](Get-Content $PhotoFile -Encoding byte)
            #Update User Profile Photo
            $user.put("thumbnailPhoto",  $photo )
            Write-Host $user.displayname " Photo has been updated."
Once imported, You can find the "thumbnailPhoto" property updated in AD User's properties.
import pictures from active directory to sharepoint 2010
BTW, User profile picture can be from any where! Not just AD, but any File Server, SharePoint Library, etc. So you can proceed by setting up a ProfileURL mapping and execute below steps.

Step 2: Configure Property mapping between SharePoint and Active Directory and Run FULL Profile Import.
Once user profile pictures are imported to Active directory, the next step is to make SharePoint aware of the Property by creating a Property Mapping. Go to:
  • Central Administration >> Manager Service Application
  • Click on "Manage" on User Profile Service Application
  • Click on "Manage User Properties"
  • Edit the "Picture" property
    import user profile photos from active directory into sharepoint 2010
  • We don't want users to override the photo from AD. So select "Do not allow users to edit value for this property" option
    import ad photos into sharepoint 2010
  • Specify the User Profile Connection, Attribute as "thumbnailPhoto" and direction as "Import"
    sharepoint 2010 import picture from active directory
  • click "Add" button and then "OK".
So, we've done mapping the AD property thumbnailPhoto with SharePoint via “PictureURL” User Profile property.

Trigger FULL User Profile Synchronization 
Since UPS didn’t know about this field previously, We've to Run FULL user profile sync. From User Profile Service Application, click on "Start Profile Synchronization" >> Select "Start Full" >> Click "OK" button.
 import pictures from active directory to sharepoint
wait for the user profile Synchronization to complete, and then proceed to next step. So now, we've import user profile photos from active directory into SharePoint 2010.

Step 3: Run Update-SPProfilePhotoStore cmdlet to generate thumbnails for SharePoint user profile picture.
SharePoint 2010 requires the thumbnails to be within 10kb size of 32x32, 96x96, 144x144 px resolutions. So, We've to instruct SharePoint to generate the image thumbnails and re-configure user profiles to reference the thumbnail.

PowerShell Script to create thumbnails in the right sizes and maps the images to the user profiles:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Update-SPProfilePhotoStore -CreateThumbnailsForImportedPhotos 1 -MySiteHostLocation  http://<My Site Host Web App URL> 
Make sure You have Administrator access and "FULL" control Permissions on User Profile Service Application.  Otherwise, You will get "Update-SPProfilePhotoStore: Object reference not set to an instance of an object." Error!
sharepoint 2010 import photo from active directory
In some cases, It’s also important to note that you must be a site collection administrator of the ‘My Site Host’, and also have administrative access to the SQL Databases. On successful execution, SharePoint 2010 Stores user profile pictures under My site Host's, "User Photos" library. E.g.

If you don't see Thumbnail photos appear even after full synchronization, One cause could be: You'll have to enable "CrossDomainPhotosEnabled" property of the web application to "True"
 $WebApp = Get-SPWebApplication
 $WebApp.CrossDomainPhotosEnabled = $true

Verify the Result: Navigate to My site Personal profile (person.aspx) page and verify the new photo. Same Procedure applies to SharePoint 2013 also.
sharepoint 2010 import user photo from ad
Remember, SharePoint search will still show you the old photo until the next incremental search crawl takes place on the content source with your sps3:// provider mapped!

On Going Maintenance: Once AD Profile photo is updated down the line, SharePoint 2010 user profile synchronization will pick the photo. But still we've to make the photo ready for SharePoint by executing Update-SPProfilePhotoStore cmdlet on schedule basis.

So, Its a good idea to schedule a script in Windows Task scheduler to run Update-spprofilephotostore cmdlet after completing FULL profile import. Say, You have the script in a file "SPProfilePhotoStore.ps1" under "D:\Scripts".  Schedule a PowerShell script in Windows task Scheduler and enter "c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe "& 'D:\Scripts\Update-SPProfilePhotoStore.ps1'" in Program to execute.

 or in arguments box, you can directly enter: -NonInteractive -NoProfile -Command "& {Add-PSSnapin Microsoft.SharePoint.PowerShell;Update-SPProfilePhotoStore -MySiteHostLocation https://<My site Host URL> -CreateThumbnailsForImportedPhotos 1}"

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:


  1. Hello there,
    thank you for keeping up. After doing this, all the pics are well synced from AD into Sharpeoint Mysite, & appears on users' profile, but in search we can't see these pictures for some of the users (most actually)

    1. Check your Search service includes People search content source! Trigger a full crawl once.

  2. Hi

    I have a question. I wrote a similar import script which updated my AD user properties and also the thumbnail photo from my on prem SharePoint 2013 intranet. Did the UPS but noticed I hadn't got any photos displayed in Mysites. I had ran the Update-SPProfilePhotoStore but I had forgotten the 'optional' -CreateThumbnailsForImportedPhotos $true. One thing I have noticed with this parameter is the (L) photo stored on mysites is very pixelated. Has anyone noticed this? I will need to fix either update photos in profile directly with PS script or somehow run the Update-SPProfilePhotoStore but without the optional param. Any advice would be welcome as I have loads to do..

  3. My pixelation was due to the file that I uploaded onto AD being in .png format. My advice is always use .jpgs.

  4. Hi,

    Profile pictures are not importing to sharepoint. I could see either cross mark or blank photo and also i could see only GUID's in user photo list in my site host. I ran the full sync and also ran the update profile store command but still the same.

    Photos exists in sync database but not in profile database. Please help me in fixing this.

    Thanks in Advance.


Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...