{"id":451,"date":"2013-10-08T08:43:37","date_gmt":"2013-10-08T08:43:37","guid":{"rendered":"http:\/\/dollarunderscore.azurewebsites.net\/?p=451"},"modified":"2017-06-05T20:45:45","modified_gmt":"2017-06-05T18:45:45","slug":"getting-pictures-converted-for-thumbnailphoto-to-be-used-in-lyncoutlook-convertto-adthumbnail","status":"publish","type":"post","link":"https:\/\/p0wershell.com\/?p=451","title":{"rendered":"Getting pictures converted for ThumbnailPhoto to be used in Lync\/Outlook (ConvertTo-ADThumbnail)"},"content":{"rendered":"<p>There are obviously a lot of things that needs to be migrated when changing mail platform, one of those things that are a &#8220;very nice to have&#8221; is user pictures\/thumbnails which shows up in Outlook, OWA, Lync and so on&#8230;<\/p>\n<p>But this can be quite a challenge. The pictures are stored in the &#8220;ThumbnailPhoto&#8221;-attribute as a byte array, which needs the picture size to be less than 10 kb to work in lync\/outlook (actually, the &#8220;Active Directory Users &amp; Computers&#8221;-snapin wants it under 8 kb to be shown in the attribute editor so this is what we choose).<\/p>\n<p>The pictures from Notes are &#8220;user generated&#8221;, they can be gif, jpg, png, bmp or something else, and I&#8217;m guessing this would be the case for many large organisations out there.<\/p>\n<p>The solution we used was to add a step in our &#8220;Notes to Active Directory&#8221;-script to check if a picture is available, if it is, it uses a small &#8220;advanced function&#8221; I wrote to convert the picture to a byte array, and save a copy of the new file on disk, it&#8217;s called <a title=\"ConvertTo-ADThumbnail\" href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2014\/07\/ConvertTo-ADThumbnail.ps1_.txt\">ConvertTo-ADThumbnail<\/a>. It also output&#8217;s the changes in size if that&#8217;s needed.<\/p>\n<p>It looks like this:<br \/>\n<code><\/code><\/p>\n<pre>PS H:\\&gt; ConvertTo-ADThumbnail -PictureFile .\\MyPrettyPicture.jpg<\/pre>\n<p><code><\/code> OrgFilename : .\\MyPrettyPicture.jpg OrgFileSize : 33,748046875 OrgFileWidth : 400 OrgFileHeight : 300 NewFilename : H:\\\\MyPrettyPicture-ADThumbnail.jpg NewFileSize : 8,9111328125 NewFileWidth : 336 NewFileHeight : 252 ThumbnailByteArray : {255, 216, 255, 224&#8230;}<\/p>\n<p>&nbsp;<\/p>\n<p>To actually write the &#8220;ThumbnailByteArray&#8221; to the user object you do something like this:<\/p>\n<p>[powershell]<\/p>\n<p># Set the folder paths<br \/>\n$PictureFilePath = &#8216;.\\Path\\MyPrettyPicture.jpg&#8217;<br \/>\n$ADThumbnailPictureFolder = &#8216;.\\TheFolderISave\\ADThumbnails&#8217;<\/p>\n<p># Load the byte array<br \/>\n$UserPicture = [byte[]] $(ConvertTo-ADThumbnail -PictureFile $PictureFilePath -OutputDir $ADThumbnailPictureFolder | select -ExpandProperty ThumbnailByteArray)<\/p>\n<p># Write it to Active Directory<br \/>\nSet-ADUser -Identity &#8216;MySamAccountName&#8217; -Replace @{ thumbnailPhoto = $UserPicture }<\/p>\n<p>[\/powershell]<\/p>\n<p>The cmdlet handles most picture formats, and shrinks them until they are small enough. You can set the file size, output folder path etc. with parameters.<\/p>\n<p>I have tested the code on 1000+ pictures, so far so good \ud83d\ude42<\/p>\n<p><em><strong>If you missed the link above, the code is available <a title=\"ConvertTo-ADThumbnail\" href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2014\/07\/ConvertTo-ADThumbnail.ps1_.txt\">here<\/a>.<\/strong><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are obviously a lot of things that needs to be migrated when changing mail platform, one of those things that are a &#8220;very nice to have&#8221; is user pictures\/thumbnails which shows up in Outlook, OWA, Lync and so on&#8230; But this can be quite a challenge. The pictures are stored in the &#8220;ThumbnailPhoto&#8221;-attribute as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[831,131,111,21],"tags":[281,1081,291,301,271],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3Zj0A-7h","_links":{"self":[{"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/posts\/451"}],"collection":[{"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/p0wershell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=451"}],"version-history":[{"count":0,"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/posts\/451\/revisions"}],"wp:attachment":[{"href":"https:\/\/p0wershell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p0wershell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p0wershell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}