Adding Pictures to Active Directory

I came across this challenge when installing Lync 2013 where a customer did not have Exchange 2013 and therefore unable to us HD pictures in Lync and Exchange. Prior to Exchange 2013 the only way to import pictures is to use Active Directory to store the image. Storing images in AD have specific requirements. The format must be .jpg or .gif and the image size must be no more than 48×48 pixels. There is a cool image resizer tool that someone has made compatible with windows 7 (it works for windows 8 too) https://imageresizer.codeplex.com/releases/view/30247 Anyway to achiever my goal I created a CSV file which includes the column headers ADUserName and Picture. In the ADUserName column add the samAccountName of the user and in the Picture column add the literal location of the picture you want to use e.g c:\pictures\user.one.jpg

The rest is done by PowerShell

#change parameters here
 $Log = New-Item -ItemType File -Path "C:\ADPictureLog.txt" -Force
 $File = "C:\ADPictures.csv"
 #Import csv
 $usercsv = Import-Csv -path $file -Delimiter ','
#Check if user file is empty.
 if ($Usercsv -eq $null)
 {
  write-host "No Users Found in Input File"
  exit 0
 }
$count = $Usercsv | Measure-Object | Select-Object -expand count
Write-Host "Found " $count "Users to import."
 Write-Host "Processing Users.....`n"
 $index = 1
ForEach ($User in $Usercsv)
 {
 Write-Host "Processing User " $index " of " $count
 $ADUserName = $User.ADUserName
  $UserPicture = $User.Picture
 $CheckAD = Get-ADUser -Identity $ADUserName
 if ($CheckAD -eq $null) {
  $notinad = $true
  Write-Host "User " $ADUserName " is not found in AD. Double check spelling, etc." -Foregroundcolor Red
  Add-Content -Path $Log -Value "$($ADUserName) is not found in AD. Double check spelling, etc."
  }
else {
  #import photograph
  $Photo = [byte[]](Get-Content $UserPicture -Encoding byte)
  Set-ADUser -Identity $ADUserName -Replace @{thumbnailPhoto=$Photo}
  Write-Host "User: " $ADUserName " Photo has been updated with " $UserPicture " Ok"
  Add-Content -Path $Log -Value "$($ADUserName) has been updated with a photograph $($UserPicture)"
  }
  $index++
 }
 Write-Host "Picture Updates have been Completed"
 Add-Content -Path $Log -Value "End of Log"

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