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.

52 comments

  1. Eric says:

    I can’t get this attribute to save to the Picture profile property because the Picture property is of type Url. Also I can’t change the Pictury data type. I don’t even see that type type available in SharePoint if I were to create a new profile property.The thumbnailPhoto in AD is of type OctetString. How did you handle this?

  2. Brent Harvey says:

    Eric,

    I did not need to change the data types of thumbnailPhoto in AD or the Picture property in Central Admin, which is set to Url.

    If you look in Active Directory, do you see values in the thumbnailPhoto field?

    In Central Admin, if you go into “Manage Service Applications”, and then into your “User Profile Service Application”. If you head into “Manage User Profiles”, search for that person which you just checked, and click “Edit My Profile”. Does the image show up?

    • Eric says:

      Hi Brent,

      Thanks for the info. Turns out I was just being a dummy and not pressing the ‘Add’ Button. I was just pressing ‘Ok’ and expecting it to save all the changes (as it was in SP2007). Once I did that then everything worked great.

      By chance do you know if it will be necessary to run the powershell commands again once new users are added, or does this just configure SP for all existing and future users?

      Thanks,
      Eric

      • Brent Harvey says:

        Eric,

        The PowerShell commands will need to run periodically. This is the part that takes the image that is stored in the User Profile store and creates thumbnails of each picture, which are then placed into the My Site Host’s User Photos library. As well as updating the property value in the profile database.

  3. Trey Gross says:

    I appreciate your information and it was helpful. However, I cannot get the powershell to run. The only variable you have is what’s in quotes correct? And am I to run it on the SharePoint 2013 server which is running UPS?

    • Brent Harvey says:

      Correct, run the PowerShell commands on the SharePoint server running UPS. Also correct that the only variable is $mySitesUrl. Make sure that is the valid path to the MySites host web application.

      Also, because of wrapping, the third command wraps into the next line looking like 4 commands. It should be a total of 3 commands, so the third command is
      ‘Update-SPProfilePhotoStore –MySiteHostLocation $mySitesHost
      –CreateThumbnailsForImportedPhotos $true’

  4. Hayden says:

    I’ve followed your post exactly but I still can’t get the profile picture to show up. Any suggestions?

  5. Nigel Bragg says:

    Afternoon Gents,

    I have exactly the same problem but I’m trying to import photos into SharePoint 2007.
    I have AD running at 2008 R2 with all staff photos imported using the thumbnailPhoto attribute. The photos work fine in Outlook and Lync 2010.

    In ‘User Profile and Properties’, ‘View Profile Properties’ the picture property cannot be changed from a URL type. The Source Data Connection is set to ‘Master Connection’, and the Data source field to map is set to ‘thumbnailPhoto’. I have run a full import but the photos do not appear.

    Any help appreciated…

    • Eric says:

      Hi Nigel,

      SP 2007 expects a url path to the picture. This can be handled a couple of ways.

      First, you could simply place all pictures into a picture library at the top level of your site collection and then populate the url with a path to that picture. This works but is not very automatic.

      For a more automatic version you will need to a little programming. One of our guys wrote a small web app that allows users to update their profile picture in AD. This same app has a basic page that only displays the picture (once saved). In other words it doesn’t have any navigation or links or anything, just the pic. As the picture is saved to AD the URL path to this basic picture page is also saved into an AD field such as ‘Web page’ or the ‘Other’ next to ‘Web page’. Then in the SSP we map that ‘Web page’/’Other’ field (internally named wWWHomePage/url) to the Picture property to populate the URL. SharePoint does the rest to display the picture.

      for a half way automatic solution you could do the mapping above, but then an administrator fills in the picture path into AD. Once this is done for the existing employess then usually it is only done when creating new users. This way users don’t have access to change their own picture.

  6. Shannon says:

    Thank you for this great information, Brent; however, ADUser is not recognized on my AD server for some reason. What would be an alternative, please? Thanks ever so much! ~ Shannon ~

    • Brent Harvey says:

      The PowerShell commands are “Get-ADUser” and “Set-ADUser”, which are available if you have installed the Windows Remote Server Administration tools. Try installing that first if the commands are not recognized.

      • Shannon says:

        Thank you Brent for your prompt reply! I am back at it again. I was very excited when finally being able to successfully add my picture to Active Directory; however, when trying to add any of the other 2,000 employee pictures, it doesn’t seem to recognize the “Get-Content $filePath -encoding byte” line….. “-encoding” in particular. It accepted it when performing this function on my own profile, but no others. I am an administrator and went so far as to log in with another administrator’s credentials with the same result. I appreciate any advice. Thank you so much! 🙂

        • Brent Harvey says:

          It should be fine with just your credentials.

          There is a default max file size of 100k for the AD attribute thumbnailPhoto. Are your images over that size?

          Try uploading one small image < 10k for another user, and see how that goes.

  7. Mark says:

    Do you know if this option is in SharePoint 2013 Foundation? I cant seem to find it.

    • Brent Harvey says:

      No. The User Profile Service is not part of SharePoint Foundation, you will need Standard Server or Enterprise.

  8. Matthew Damp says:

    Minor point on the last PowerShell script: you should run that script as and farm service account. It will error out with a error similar to “Update-SPProfilePhotoStore : UserProfileApplicationNotAvailableException_Logging :: UserProfileApplicationProxy.ApplicationProperties ProfilePropertyCache does not have [random GUID]”

  9. Keith says:

    When I run the second command defining ($mySitesHost) I get the error “Get-SPSite : The term is not recongnized as the name of a cmdlet, function, etc…..” Am I missing something? Thanks for the help 🙂

    • Brent Harvey says:

      You will need to run the SharePoint Management Shell. Or if you are in PowerShell just run the command:

      Add-PSSnapin Microsoft.SharePoint.PowerShell

      That will load the SharePoint commands.

  10. Kristin says:

    Hi Brent,

    thanks for the post.
    I tried to execute you last command and got a UserProfileNotAvailableException. Do you have any idea?
    I’m sure I used the right MySiteHost and the services are running.
    I also get other AD fields synchronized but not the pictures.

    Thanks in advance.
    Kristin

    • Brent Harvey says:

      Make sure that the user that you are running the commands as, has Active Directory rights AND access to the User Profile Service and/or a Farm Account. Maybe try the same account as the User Profile Sync.

      Does any pictures get loaded? If you look at the list of user profiles, does any have pictures?

  11. Rene D says:

    Hi there,
    I have been trying several things but I end up with to following error:
    Update-SPProfilePhotoStore -MySiteHostLocation https://testmy.XXXXX.nl/
    Update-SPProfilePhotoStore : The pipeline has been stopped.
    At line:7 char:27
    + Update-SPProfilePhotoStore <<<< -MySiteHostLocation https://testmy.XXXXXX.nl/
    + CategoryInfo : InvalidData: (Microsoft.Offic…ofilePhotoStore:SPCmdletUserProfilePhotoStore) [Update-SPProfilePhotoStore], PipelineStoppedException
    + FullyQualifiedErrorId : Microsoft.Office.Server.UserProfiles.PowerShell.SPCmdletUserProfilePhotoStore

    What am I doing wrong??

    Greets, René

    • Brent Harvey says:

      Rene,

      The “InvalidData” part of the error caught my eye. In the “Manage Profile Server” section, go back into the “Picture” attribute and see if the “Property Mapping for Synchronization” looks like the image above. Its easy to over look clicking the “Add” portion of it.

  12. Kjell Brandes says:

    I have to ask you about an issue.
    Everything in your tutorial is great, but I’m getting a problem when browsing user profiles.
    The path to images is wrong, I can’t understand what I’m doing wrong..
    The path to the pictures on my server is as below:
    http://serveraddress.com/mysiteUser Photos/Profile Pictures/s2050_SThumb.jpg
    There is a missing slash in this URL?! between “MySite” and “User Photos”.
    Anyone with ideas on this? I cant resolve why there is missing a slash in the URL to the image, If I’m manually ad the slash the images are there so they have been rendered as supposed.

    Many thanks again for a great tut.

    reg
    Kjell

    • Brent Harvey says:

      Thanks Kjell.

      If you go into Central Admin and look at the user’s profile in the User Profile Service, does the profile picture show up there?

      If not, an option may be to try and run the Update-SPProfilePhotoStore specify the NewBaseURI switch with a trailing slash.

      http://technet.microsoft.com/en-us/library/ff607547.aspx

      • Senol Arabaci says:

        Hi Brent,Thanks for this post.
        I have the exact same problem as Kjell. When I put the slash the picture shows but everyone’s picture has an X on the picture and the URL is without a slash on the Central Admin Properties page. I tried assigning a new URL with NewBaseUri but Update is having problem finding the photos. This is the error I get.
        Update-SPProfilePhotoStore : Error processing the photo URL
        http://serveraddress/sites/mysiteUser Photos/Profile Pictures/USERNAME_MThumb.jpg for user DOMAIN\USERNAME:
        System.Net.WebException: The remote server returned an error: (404) Not Found.
        So, it is looking for photos at URL without a slash. Can’t figure out how to get it to look at the address with slash. I already put the old address with and without slash and new address with slash with no success when updating the URL.
        Thanks
        Senol

        • Brent Harvey says:

          Senol,

          Try running the original Update-SPProfilePhotoStore as an administrator of MySites, or someone that explicitly has full control on the “Profile Pictures” library.

          Since they are appearing, they make it from AD to SharePoint, it just seems like they are then not being set properly in MySites.

  13. Rahul says:

    For me every thing went fine I run both the PowerShell commands for setting the image in AD as well Updating it to SharePoint but still I can’t see the image in SharePoint UserProfile. I appreciate any advice. Thank you so much

    • Brent Harvey says:

      Have you ran a Full user profile import?
      Also, go back into your Picture property and make sure the Active Directory import map is there. That part is easy enough to select but not add.

      • Deep says:

        Brent, awesome write. I am getting the exact error that Rahul is getting. I have set the property map, and it imports all the data, but the thumbnailPhoto.

        • Brent Harvey says:

          Deep,

          Make sure that the data is in Active Directory. Look at the thumbnail property to make sure that the value is a bunch of hex characters.

          Also, make sure that the last PowerShell command is ran by someone with rights to edit AD.

  14. Moe says:

    Hi Brent,

    I followed your directions a while ago and it worked for me. The users’ photos showed up in AD as well as SharePoint 2013. However, it is now coming to my attention that a few users are missing photos.

    1)These user photos show up in Outlook and AD (as hex value)
    2)In SharePoint, I can see the pics when I mouse over the user’s picture box – a pop-up shows the pic, but not in the actual box.
    3)Photos for these specific users are also missing in the UPS

    What am i doing wrong?? Thanks much!

    • Brent Harvey says:

      Can you narrow down the differences between the photos that do show up vs don’t.

      I believe there is a size limit to the file size and make note of the extensions.

  15. Justin M says:

    I found that after adding the thumbnailPhoto attribute, nothing was being added to the user profile (verified this by watching miisclient). Running a full sync got the property to go into the user’s profile and allowed the photo to show up.

    I’ve always thought that making any changes to the user profile properties via Central Admin required a full sync because it changes the FIM metaverse. Anyways, if you find that after successfully running all the commands above you still don’t see any pictures, just try kicking off a full sync.

    • Brent Harvey says:

      Thanks for the addendum, Justin.

      • Diane says:

        Did everything as you instructed. Still seeing the gray icon in my lists. See AD pic when hovered over. Have been working on this for weeks. If you could Pleeeeez help I would be forever grateful!!

        • Brent Harvey says:

          Diane,

          If you go into My Sites, and then go into “Site Contents”. There should be a “Profile Pictures” library.

          Head in their and then into the “Profile Pictures” folder. You should see 3 version of each picture, a large, medium and small thumbnail.

          For the user(s) in question, do you see 3 versions? The one used is the _LThumb? Also, make sure you have cleared out your cache and try the page again.

          Also, are the files smaller than 100k when you added them to AD? Also what is the file extension of the photos?

  16. Ramesh Mukka says:

    In my case, not all the profile pictures were moved to “User Photos”. For missing pictures, do I need to check their size on AD? Does SharePoint compress them while importing if it found size more than 100KB? What could be other factors that could stop pictures from importing. Those missing pictures are available on outlook and Lync. Kindly advise.

    • Ramesh Mukka says:

      When i checked SyncDB, all profile pictures do exist in hexadecimal codes. But not all exists on Profile DB. Even after I ran the Update-SPProfilePhotoStore command, it doesnt sync into ProfileDB. What do you think going wrong here?

      • Brent Harvey says:

        Ramesh,

        There is a 100 kb limit. So for those that did not make it, double check the size of the image and their extension. Not all image extensions are supported.

  17. Ryan says:

    I’m running into an issue where the mysites url isn’t correct. It looks like this: https://example.com/sites/mysitesUser%20Photos/Profile%20Pictures/user_MThumb.jpg I’m missing a slash after mysites. Have you seen this happen before?

    • byron delamatre says:

      Ran into this as well. Try the OldBaseUri and NewBaseUri parameters.

      $oldUri = “https://example.com/sites/mysitesUser%20Photos/Profile%20Pictures/”
      $newUri = “https://example.com/sites/mysites/User%20Photos/Profile%20Pictures/”
      Update-SPProfilePhotoStore -OldBaseUri $oldUri -NewBaseUri $newUri

    • Max says:

      Hi, Rayan. I have the same bug. When I use subsite of root site of site collection as My Site Host. It concats urls of web and user pics library with out delimiter sign. But I’ve found one interesting thing in Profile DB. There is one view UserProfile, if you execute it, you will see, profile info and PictureUrl ofcourse, you can open in disign mode this view and see exact DBs where data are. I tried fix url in Profile DB, but it didn’t help. If you find solition, let me know.
      Cheers.

    • Max says:

      Rayan, I found solution. It’s a little bit dirty, but it works. First of all you need make correct urls (use SQL Managment Studio) execute script, like this <update dbo.UserProfile_Full set PictureUrl = REPLACE(PictureUrl, 'http:///personal‘, ‘http:///personal/’)>. In my case, I just add / throught REPLACE.
      Then you need update another table:
      update userProps set userProps.PropertyVal = convert(varchar(256),uprof.PictureUrl)
      from [Profile DB].[dbo].[UserProfileValue] as userProps
      left join [Profile DB].[dbo].[UserProfile_Full] as uprof on userProps.RecordID = uprof.RecordID
      where PropertyID = 23
      In my case 23 it’s id of PictureUrl property, if you execute select of this table, you will see id of your PictureUrl property. As you see, I just move values from one table to another and use join by RecordID, it’s unique User profile Id.
      I hope, it helps you.
      Cheers.

  18. Don Van Fleet says:

    Great post. I do have a couple of questions:

    1) Once this is complete, will images be automatically synchronized moving forward?

    2) Also, will the images be locked down in SharePoint, or will users be able to edit them?

    3) Related–if it’s not locked down, can it be?

  19. Craig Bonvechio says:

    Seemed to go perfectly but never could get this to work. Spent 3 hours on the phone with SharePoint support still no luck. One thing I noticed when adding the property mapping for synchronization in my case the drop down box displayed nothing so I typed in thumbnailPhoto. I could find no reason why the box did not display the attributes. I must have permission I can import user profiles completely other than photos.

    • Craig Bonvechio says:

      It isn’t well documented but you cannot use the Active Directory Import in SharePoint and bring in pictures only the full SP Profile sync. That was my issue.

  20. You can certainly see your enthusiasm within the article you write.

    The arena hopes for even more passionate writers like you who are not afraid to say how they believe.

    Always go after your heart.

  21. abdul says:

    Great Post!!

  22. Ashwin says:

    How often do we need to run the update-spprofilestore command? for eg if i have new users joining to my firm on daily basis, they will be added with their photos to AD. will SharePoint incremental automatically pick the new users with pictures? or do we need to run the update-spprofilestore on a daily basis?

Leave a Reply

Your email address will not be published. Required fields are marked *

Fuir FLuUYA 0X

Please type the text above: