Outlook, OCS, Lync user pictures import with PowerShell

The Outlook 2010 and the Lync 2010 has a fancy feature that shows the picture of the users, which stored in the Active Directory. The Exchange 2010 introduces the thumbnailPhoto attribute for the User objects that can contain the photo. There are multiple ways to import pictures into the AD; one of the easiest is the Import-RecipientDataProperty Exchange commandlet, but what can we do if we have not installed the Exchange 2010? There are several 3rd party applications available for picture uploading, but if I need to do something more than twice, I automate it. In this reason I chose a PowerShell script, which easily schedulable. In my previous article I wrote about the picture modification. That was the prerequisite of the user pictures that stored into the Active Directory. It is easy to import and export pictures with PowerShell.

There are only two lines needs to import a photo.

  $photo = [byte[]](Get-Content $userPhotoLocation -Encoding byte) $a = Set-ADUser $userSamAccountName -Replace @{thumbnailPhoto=$photo} 

Sometimes needs to download all photos. The following script part downloads all user photos, which user name begins with ‘user’.

  $adusers = Get-ADUser -filter 'Name -like "user*"' For ($i = 0; $i -lt $adusers.count; $i++){ $destination = "c:\tmp\export_" + $adusers[$i].SamAccountName + ".jpg" Write-Host $destination $user = Get-ADUser $adusers[$i] -Properties thumbnailphoto $user.thumbnailphoto | Set-Content $destination -Encoding byte 

You can use the Get-ADUser command, if you import the ActiveDirectory modul into the powershell.

1 thought on “Outlook, OCS, Lync user pictures import with PowerShell”

  1. It always amazes me how Blog owners for example yourself can find some time as well as the commitment to carry on Producing great blogposts your site https://letitknow.wordpress.com/2012/02/23/outlook-ocs-lync-user-pictures-import-with-powershell/ is wonderful and one of my personal have to read personal blogs, I had been more than impressed with the blog post Outlook, OCS, Lync user pictures import with PowerShell Let IT know I simply want to say thanks and also well done Best wishes horny

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