John Yassa's Blog

Home » Exchange 2010 » Add or Update a User Picture to the Active directory

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: