User Photo in Exchange, Lync and Active Directory

There are several posts out there about how to upload users’ photos into Active Directory (AD) so they can be used by Exchange or Lync, but very few on how this works or how to export them if we need to.

In AD we can use images no greater than 96×96 pixels in resolution and 100KB or smaller in size. This looks ok in the Lync and Outlook client, but results in a blurred photo when Lync, for example, attempts to upscale the image for use in a conference.

In Lync 2013 (and Skype for Business Server 2015) photos can be stored in the user’s mailbox (when using Exchange 2013), allowing for photo sizes up to 648×648 pixels. In addition to that, Exchange automatically resizes these photos for use in different products as needed:

  • 64×64 pixels (96 dpi, 24 bit depth, approx. 2KB), the size used for the AD thumbnailPhoto attribute. If we upload a photo to Exchange, Exchange will automatically create a 64×64 pixel version of that photo and update the user’s thumbnailPhoto attribute. However, if we manually update the thumbnailPhoto attribute in AD the photo in the user’s mailbox will not automatically be updated. This photo is only used by Lync 2010 or legacy clients, so we are ok;

  • 240×240 pixels if the original picture is larger than 240, otherwise 96 (96dpi, 24 bit depth, approx. 8KB), for use in Outlook, OWA, Skype for Business Web App, and Skype for Business;

  • 648×648 pixels for use in Skype for Business and Skype for Business Web App.

Importing Photos

To use high resolution photos, we have to use the Set-UserPhoto Exchange cmdlet:

Set-UserPhoto “Nuno Mota” -PictureData ([System.IO.File]::ReadAllBytes(“D:\Photos\nuno.jpg”)) –Confirm:$False

As already mentioned, the Set-UserPhoto cmdlet does two things: it stores a copy of a high resolution image in the user’s Exchange mailbox, and stores a copy of the photo as a 64×64 image in the thumbnailPhoto AD attribute.

Exporting Photos

To check someone’s photo, we can use Exchange Web Services and the following URL (updating the user’s email and maybe image size):

https://mail.domain.com/ews/Exchange.asmx/s/[email protected]&size=HR648x648

If we want to export a user’s photo from AD, we can PowerShell and the following commands:

$photo = (Get-ADUser nuno -Properties thumbnailphoto).thumbnailphoto

We can now save this photo into a JPEG file and or import it directly to a different user for example (usefull if the user gets a new account):

Set-Content “D:\Photos\nuno.jpg” -Encoding byte

Set-ADUser mota -Replace @{thumbnailphoto = $photo}

However, if we are using Exchange 2013, we should use Exchange cmdlets to manage users’ photos. This way we can export the 648×648 pixels photo from the user’s mailbox instead of the small one from AD:

(Get-UserPhoto nuno).PictureData | Set-Content “D:\Photos\nuno.jpg” -Encoding byte

If you want to use high resolution photos in Lync as well, you might want to ensure you update your Lync Client policy with a MaxPhotoSizeKB of at least 100 instead of just 30.

About The Author

6 thoughts on “User Photo in Exchange, Lync and Active Directory”

  1. Andrey Novokreshchennykh

    Hello Nuno,
    Thanks for your article!
    Can you explain what happens when we change photo from Outlook 2013/2016 (for mailbox in Exchange 2013/2016)? And what happens when we change photo from Skype for Business client?
    Also I interested, can I set different photos for Outlook and SfB client.

    1. Hi Andrey,

      You are welcome! 🙂
      The photo is always kept on the user’s mailbox. So, no matter where you change it from, it always get updated there, because that is the only location where it exists (apart from a small thumbnail in AD, but that’s no longer used by Exchange or Skype). As such, you simply cannot have different photos.

      Regards,
      Nuno

  2. Are there alternatives to set-userphoto and get-userphoto, like some sort of API? We built a web-based phonebook app for our Intranet site that retrieves the low-res photos in AD. It would be nice to use the high-res photos from Exchange. The app has an admin module that allows helpdesk staff to upload/replace the low-res photos in AD. It would be nice if they could upload a high-res photo to Exchange, which would automatically replace the low-res photo in AD with the new one. We can’t give our helpdesk staff any access to any native Exchange admin tools, so we’d would HAVE to use an API.

    1. Hi Mark,

      You can’t update the app to connect to Exchange and use the Set-UserPhoto cmdlet? I am sure you can also use Exchange Web Services to set users photos, but I have never tried it…

      Regards,
      Nuno

  3. Not too sure what to do after entering the following:

    Input
    ——-
    Set-Content “P:\Photos\username.jpg” -Encoding byte

    Output
    ———-
    cmdlet Set-Content at command pipeline position 1
    Supply values for the following parameters:
    Value[0]:

    1. Hi,

      The entire line should be: “(Get-UserPhoto nuno).PictureData | Set-Content “D:\Photos\nuno.jpg” -Encoding byte”
      You are basically passing the photo through a pipe and writing it to a file.

      Regards,
      Nuno

Leave a Comment

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top