Add or Update a User Picture to the Active directory

How Can We Help?

You are here:
< Back

Add or Update a User Picture to the Active directory

This is a quick article to show how easy it is to update an Active Directory user account with a photo of the user.

The Active Directory thumbnail Photo attribute is used by several applications to display a picture for the user account. Microsoft Outlook is one such application that uses this attribute to display the picture of people you send and receive emails to and from (within an Active Directory domain).

Example

Now, for the fun bit! Let’s assume we have user John, and we have saved John’s photo to C:\photos\John.jpg

In two lines of code, we can update John’s photo.

Get the photo, using the Get-Content Power Shell cmdlet, using the encoding type byte. Store the photo as a byte array in the $photo variable. Then update Active Directory using the Set-ADUser cmdlet, passing the byte array ($photo) to the thumbnailPhoto attribute.

$photo = [byte[]](Get-Content "C:\photos\John.jpg" -Encoding byte)            
Set-ADUser John -Replace @{thumbnailPhoto=$photo}

To shorten this to one line of code, we could write this as;

Set-ADUser John -Replace @{thumbnailPhoto=([byte[]](Get-Content "C:\photos\John.jpg" -Encoding byte))}

Now the Photo of John will appear in Outlook and Lync as below:

1- Outlook

outlook

2- Lync

Lync