Archive for May 13, 2013

Adding Pictures to Active Directory and Show in SharePoint 2013

Adding Pictures to Active Directory and Show in SharePoint 2013

A very common setup request for SharePoint is for it to pull pictures of employees directly from Active Directory. This allows all employee photos to be managed in a central location, and give some governance to how the photos should look.

This post will take you through adding images into Active Directory and having SharePoint display it.

 

Adding Photos into Active Directory

Adding Photos into Active Directory is not as simple as opening up Active Directory Users and Computers, choosing the employee and uploading a photo. Active Directory stores photos as a bytes, so when adding images to Active Directory, you have to pass it in as bytes. Not a big challenge using PowerShell.

The following command will upload the Harvey_Brent.jpg photo into active directory for the user bharvey. I’ve ran this on the AD server.

$userName = “bharvey”
$filePath = “c:\temp\Harvey_Brent.jpg”
[byte[]]$img = Get-Content $filePath –encoding byte
Get-ADUser –filter {samaccountname –eq $userName} |
Set-ADUser –replace @{thumbnailphoto=$img}

Now, if you look into the bharvey AD user, you can see the thumbailphoto attribute is set with a list of hex values which make up the photo’s bytes.

 

Setting up Photos in SharePoint 2013

To set up SharePoint to use these photos, our first step will be to map the SharePoint “Picture” column to the Active Directory “thumbnailPhoto” column. We can do this from within the User Profile Service Application. While in the “Manage Profile Service” page, within Central Administration, click on the “Manage User Properties” link.

 

On the “Manage User Properties” page, find the “Picture” property and go into the Picture property’s edit page. This is where you will configure the mapping, as well as set other settings, e.g. if users should be able to change the image themselves. For the mapping, select thumbnailPhoto, and Import, and click the “Add”.

Publishing Photos to SharePoint 2013

Now that we have the photos in Active Directory and the mapping configured. All we need to do is run an incremental Profile Synchronization from the same “Manage Profile Service” page to get the photo(s) we’ve added into Active Directory. Then, we will just need to run another PowerShell command to make sure that the SharePoint profile photo store is compatible with SharePoint Server 2013. (This will need to be run by a user with AD edit rights).

We also specify the MySites Host site, where the images will be stored.

$mySitesUrl = “http://my.bharveyserver”
$mySitesHost = Get-SPSite –Identity $mySitesUrl
Update-SPProfilePhotoStore –MySiteHostLocation $mySitesHost
–CreateThumbnailsForImportedPhotos $true

With that, all the images that we’ve added to Active Directory are now available in SharePoint.