Wednesday, 21 June 2017

Better update your photo with powershell for windows Outlook/Lync/Skype-for-business/etc

Yesterdays post required the Remote Server Administration Toolskit installed.

Here I show how to do it without that, just using powershell. Thanks to maxx-ode who gives the answer on this Microsoft Technet Forum post .

This code will set picture.jpg as your thumbnail picture.

$root = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().GetDirectoryEntry()
$search = [System.DirectoryServices.DirectorySearcher]$root
$search.Filter = "(&(objectclass=user)(objectcategory=person) (samAccountName=$env:username))"
$result = $search.FindOne()
$user = $result.GetDirectoryEntry()
$user.put("thumbnailPhoto", [byte[]](Get-Content "picture.jpg" -Encoding byte))

or you want to delete the photo:

$user.putex(1, "thumbnailPhoto", "")

but if you are re-using $user you may want to precede with: $user.refreshcache()

If you get an error like this:

Exception calling "setinfo" with "0" argument(s): "A constraint violation occurred."
At line:1 char:1
+ $user.setinfo()
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

then it could be that your picture is too big, keep it less that 100K, and ideally much smaller than that.
A 100x100 picture should be around 4K which is more ideal.


  1. $result = ([ADSISEARCHER]$("samaccountname=$env:username")).findone()

    $user = $result.GetDirectoryEntry()

    $user.put("thumbnailPhoto", [byte[]](Get-Content "photograph.jpg" -Encoding byte))


  2. Expectations are high regarding the new features which are going to come in with the launch of FIFA 18.
    And particularly after an exhilarating release of trailer a few days back, fans have gone really crazy.
    A high-quality game is definitely on the cards. Want to know more about it? Click Here