Active Directory: Add or Update a User Picture in AD using PowerShell

Active Directory: Add or Update a User Picture in AD using PowerShell


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 attribute is used by several applications to displays a picture for a user account. Microsoft Outlook is one such application that uses this attribute to display the picture of people you send and receive emails from (within a corporate Active Directory domain).

Before using the PowerShell commands below, you need to have the Active Directory module for PowerShell installed. You can find out about installing and using the Active Directory module for PowerShell on Microsoft's TechNet site, here:

Active Directory Administration with Windows PowerShell
Active Directory Cmdlets in Windows PowerShell

Also note that there are constraints on the sizes and formats supported for the thumbnailPhoto Active Directory attribute. As a general guideline, keep your images to 96x96 pixels and under 10Kb.


Now, for the fun bit! Let's assume we have user Crusoe, and we have saved Crusoe's photo to C:\temp\crusoe.jpg

In two lines of code, we can update Crusoe's photo.

Get the photo, using the Get-Content PowerShell 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:\temp\crusoe.jpg" -Encoding byte)
Set-ADUser Crusoe -Replace @{thumbnailPhoto=$photo}

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

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

This article originally came from a post of Matthew Yarlett which can be found here, Add or Update a User Profile Picture (Thumbnail) in Active Directory using PowerShell with One Line of Code

Leave a Comment
  • Please add 4 and 1 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
  • Version 4. Added code formatting. Any idea why the code formatting (the border) gets lost when you edit a wiki article from IE? It seems to loose a styles directly applied to it.

Page 1 of 1 (1 items)