Sladescross's Blog

Blogging about Sharepoint related stuff

Exchange Thumbnail Photo February 22, 2011

Filed under: Exchange Thumbnail Photo — sladescross @ 11:16 am

http://www.exchangeinbox.com/article.aspx?i=156&t=7&all=1

In the past, doing this was only possible through custom code. Exchange 2010 makes it possible – and easier – via a new PowerShell command. The process is rather simple, modify an attribute in AD and then upload photos using the Import-RecipientDataProperty cmdlet. Because the images you upload to AD are so small (typically between 3-5KB), the NTDS database size should not be a concern; imagine a 3KB image for 100 employees – this will increase the AD database size by 300KB which is hardly overkill (even with AD replication in mind).

http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/Q_26245356.html

VBScript to read stream from file system and add through LDAP.

------------------- 
'Photos must be less than 10kb 
Const ForReading = 1 
InDir = "C:\Temp\StaffPhotos" 
Set fso = CreateObject("Scripting.FileSystemObject") 
set oIADS = GetObject("LDAP://RootDSE") 
strDefaultNC = oIADS.Get("defaultnamingcontext") 
Set theConn = CreateObject("ADODB.Connection") 
theConn.Provider = "ADsDSOObject" 
theConn.Open "ADs Provider" 
Set theCmd  = CreateObject("ADODB.Command") 
theCmd.ActiveConnection = theConn 
Set objRecordSet = CreateObject("ADODB.Recordset") 
For Each tFile In fso.GetFolder(InDir).Files 
   tName = tFile.Name 
   'Gets the persons Name from the file by stripping the extention. 
   tName = Left(tName, InStrRev(tName,".")-1) 
   'You may need to tweak this bit depending on your naming conventions. 
   strQuery = "<LDAP://" & strDefaultNC & ">;" & _ 
                             "(&(objectClass=person)(name=" & tName & "));name,adspath;subtree" 
   theCmd.CommandText = strQuery 
   Set objRS = theCmd.Execute 
   If objRS.RecordCount = 0 Then 
     MsgBox "Can't find account for " & tName 
   Else 
     Set objUser = GetObject(objRS("adspath")) 
     ObjUser.Put "thumbnailPhoto", ReadByteArray(tFile.Path) 
     ObjUser.SetInfo 
   End If 
Next 
'Stolen from http://www.ericphelps.com/q193998/index.htm 
Function ReadByteArray(strFileName) 
   Const adTypeBinary = 1 
   Dim bin 
   Set bin = CreateObject("ADODB.Stream") 
   bin.Type = adTypeBinary 
   bin.Open 
   bin.LoadFromFile strFileName 
   ReadByteArray = bin.Read 
End Function
About these ads
 

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

 
Follow

Get every new post delivered to your Inbox.

Join 63 other followers