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:
Well, this article addresses import user pictures from active directory to SharePoint 2010 step by step:
- Import user photos into the Active Directory user profile’s “thumbnailPhoto” attribute.
- Configure Property mapping between SharePoint and Active Directory and Run FULL Profile Import.
- 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 the Active Directory user profile’s “thumbnailPhoto” attribute, We can import pictures into it. For SharePoint 2010 to import user photos from Active directory, it must have this attribute populated.
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:
Let’s say, we have a 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 photos 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 )
$user.setinfo()
Write-Host $user.displayname " Photo has been updated."
}
}
Once imported, You can find the “thumbnailPhoto” property updated in AD User’s properties.
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
- We don’t want users to override the photo from AD. So select the “Do not allow users to edit the value for this property” option
- Specify the User Profile Connection, Attribute as “thumbnailPhoto” and direction as “Import”
- 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.
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 32×32, 96×96, 144×144 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 https://<My Site Host Web App URL>
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. https://mysite.crescent.com/User%20Photos
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 https://intranet.crescent.com
$WebApp.CrossDomainPhotosEnabled = $true
$WebApp.Update()
Verify the Result: Navigate to My site Personal profile (person.aspx) page and verify the new photo. The same procedure applies to SharePoint 2013 also.
Ongoing Maintenance: Once the 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 a scheduled 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 ” and ‘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}”
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.
My pixelation was due to the file that I uploaded onto AD being in .png format. My advice is always use .jpgs.
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..
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)
Check your Search service includes People search content source! Trigger a full crawl once.