Skip to content

Follow:
RSS
Twitter
marjus`s field notes
from every day work with IT and not only

* Home
* About

Lync corporate photo update script
December 16, 2011

Simple example how to update thumbnailPhoto in AD. Pictures are optimized in process and usually not exceed 3K and still good quality. Not depending on Lync or Exchange Management shell.

It easy modify this script for more complex scenarios and of course in production environment some reporting are advised, but that was not propose of this post.

Proven in field 🙂

view source
print?
01 ###############################################################################################
02 # updateadphoto.ps1
03 # v2
04 # 2011
05 # Marjus Sirvinsks (marjuss.wordpress.com)
06 #
07 # picture file names should match SAM account name
08 #
09 # Requires convert.exe; vcomp100.dll in same folder where script located.
10 # Already compiled files can be downloaded here http://www.stevieg.org/downloads/GALBatchConvert_with_ImageMagick_Convert.zip
11 # or directly from http://www.imagemagick.org
12 #
13 # Idea for picture optimization technique comes from Steve Goodman’s Exchange blog:
14 # http://www.stevieg.org/2011/01/batch-optimize-exchange-gal-photos-importing-a…
15 #
16 ###############################################################################################
17
18 # AD search root
19 $SearchRoot = “dc=domain,dc=com”
20
21 # Filter – not disbalded AD and Lync enabled user objects
22 $filter=”(&(objectCategory=person)(objectClass=User)(msRTCSIP-UserEnabled=TRUE)(!userAccountControl:1.2.840.113556.1.4.803:=2))”
23
24 # Picture source location. Can be network share.
25 $source = “C:\scripts\picturesource\”
26
27 #Temporary folder where optimazed pictures stored for review
28 $destination = “.\optimizedpictures\”
29
30 $ds = [ADSISearcher]$filter
31 $ds.SearchRoot = “LDAP://$SearchRoot”
32
33 # litle thing to remember if there is more than 1000 users.
34 $ds.PageSize = 1000
35
36 #we do not want load all properties for performance reasons
37 $ds.propertiesToLoad.Add(“samaccountname”)
38
39 $users = $ds.findAll()
40
41 if (Test-Path -path $destination) {
42
43 Remove-Item $destination* -recurse
44 }
45 else {
46 New-Item optimizedpictures -type directory
47 }
48
49 foreach($row in $users) {
50
51 $dn = $row.path
52 $sam = $row.properties.samaccountname
53 $picture = $source + $sam +’.jpg’
54
55 [string]$jpg=$picture
56
57 if ((Test-Path -path $picture) -and ($jpg -like ‘*.jpg’)) {
58
59 $filename = [io.path]::GetFileName($picture)
60 $ext=[io.path]::GetExtension($picture)
61 .\convert.exe -quality 75 -depth 8 -strip -thumbnail 96×96^ -gravity Center -crop 96×96+0+0 $picture $destination$sam$ext
62 $photo = [byte[]](Get-Content $destination$sam$ext -Encoding byte)
63 $adUser = New-Object DirectoryServices.DirectoryEntry $dn
64 $adUser.put(“thumbnailPhoto”, $photo )
65 $adUser.setinfo()
66 }
67 }

Rate this:

i

Rate This

Share this:

* Twitter2
* Email
*

Like this:
Like
One blogger likes this.

* [Thomas Kisner]

From → Lync, Powershell, Windows

One Comment

Trackbacks & Pingbacks

1. Lync Server and PowerShell – My favourite features, oneliners and scripts « msunified.net

Leave a Reply Cancel reply

Fill in your details below or click an icon to log in:

*
*
*
*

[Gravatar]
Email (required) (Address never made public)
Name (required)
Website
[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 )

Cancel

Connecting to %s

Notify me of follow-up comments via email.

Troubleshoot Lync Mobility reverse proxy »

*
Recent Posts
* Lync corporate photo update script
* Troubleshoot Lync Mobility reverse proxy
* Requesting VCS certificate
* Change SIP address domain scripts
* nice logo
*
Categories
* Lync
* OCS
* Powershell
* VCS
* Windows
*
Tags
archiving crm cu dev lync moc monitoring msi ocs powershell r2 tandberg vcs windows
*
Some useful links
* Next Hop!

*
Contact me

marjuss@hotmail.com

*
What`s on mind
2012

Blog at WordPress.com. | Theme: Titan by The Theme Foundry.

Follow
Follow “marjus`s field notes”

Get every new post delivered to your Inbox.

Powered by WordPress.com
Send to Email Address Your Name Your Email Address
[loading] Cancel
Post was not sent – check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.
[http://stats.wordpress.com/g.gif?host=marjuss.wordpress.com&rand=0.0864056984…//t.co/UgW2UsXe][http://stats.wordpress.com/g.gif?v=wpcom-no-pv&rand=0.3523585901129991&crypt=…/RE1zNDZ8S252Wl15TnBbZzdDQV9VODNdNHlpMXEmbEUybk9TWlUvUTF1WDBBcWdYLHElMVE1LGlIV1RNVV93R3phTjdWR2U2bTJGUTl0cGwlUnRNbXJTU1FBai9xPVRHUWUmUHRpTSZuOCZ6VGM5RDNOQk8/OWtDS0UtM1BmbmUwdj1UMkFYQS5GR3dMZkkuLlZCN3VZVHpRWU1PNElzekthTHRbaHlBbXVSSC82NHwtMVZ+ZENjdlc4VGQ4ZlB8K3Q9Qy9wMWxEPU9KVEhNWmRGT0Z+RV0xQ0xTJWFkVy98LHVPVXNLRSVweEV2WW1KS05qVllJSHNdQ2ZlWSxbT0EuR2lRNnphL00xR10zSVl1Qw%3D%3D]