Adding external contacts to the #Lync addressbook

There are some scenarios where it would be nice to be able to add external contacts to the Lync addresse so that they are searchable for everyone in the organization. Or at least external in the sence that the contact has a sip domain that isn’t supported in the Lync topology.

One such scenario could be an integration with an internal Cisco Telepresence solution.

The way to solve this is to add a contact object to AD that has the msRTCSIP-PrimaryUserAddress attribute populated, and the contact should be added to the address book on the next synchronization pass. I’ve made a script to create this kind of object:

Note that displayName is not required, but if you don’t add it the contact will only display the sipadress in the Lync client. I guess it’s also possible to append other AD attributes to the user such as telephoneNumber.

I got a question about telephoneNumber as well, so I’ve added it as an optional parameter in the script.
Download latest version here – Contains both versions and an example .csv

Or copy the sourcecode:


#####################################################################################
 # New-SipContact.ps1
 #
 # Creates a contact object in AD that will be included in Lync/OCS address books.
 #
 #
 # Passing parameters:
 # .New-SipContact.ps1 -cn "John Spencer" -OUpath "OU=SIPContacts,DC=contoso,DC=com" -sipaddress "john.spencer@litwareinc.com" -displayname "John Displayname Spencer"
 #
 # Written by Tom-Inge Larsen (http://www.codesalot.com)
 #
 #####################################################################################
 param($cn,$OUpath,$sipAddress,$displayName="",$telephoneNumber="")

$fullpath= "LDAP://" + $OUpath
 $SIPContactOU = [ADSI]$fullpath

$SIPContact = $SIPContactOU.create("contact", "cn=" + $cn)
 $SIPContact.Put("Description","SIP Contact Object")
 $SIPContact.Put("msRTCSIP-PrimaryUserAddress", "sip:" + $sipAddress)
 if ($displayName -ne "") {
 $SIPContact.Put("displayName", $displayName)
 }
 $SIPContact.Put("msRTCSIP-PrimaryUserAddress", "sip:" + $sipAddress)
 if ($telephoneNumber -ne "") {
 $SIPContact.Put("telephoneNumber", $telephoneNumber)
 }
 $SIPContact.setInfo()
 

I’ve also created one to bulk create contacts from a .csv file


#####################################################################################
 # New-SipContactBulk.ps1
 #
 # Creates a contact object in AD that will be included in Lync/OCS address books.
 #
 #
 # Passing parameters:
 # .New-SipContactBulk.ps1 -OUpath "OU=SIPContacts,DC=contoso,DC=com" -csv "c:newcontacts.csv"
 #
 #
 # Written by Tom-Inge Larsen (http://www.codesalot.com)
 #
 #####################################################################################
 param($OUpath,$csv)

$fullpath= "LDAP://" + $OUpath
 $SIPContactOU = [ADSI]$fullpath

$contacts = Import-Csv -path $csv -header "cn","displayName","sipaddress"

foreach ($contact in $contacts) {

$SIPContact = $SIPContactOU.create("contact", "cn=" + $contact.cn)
 $SIPContact.Put("Description","SIP Contact Object")
 $SIPContact.Put("msRTCSIP-PrimaryUserAddress", "sip:" + $contact.sipaddress)
 if ($contact.displayname -ne "") {
 $SIPContact.Put("displayName", $contact.displayName)
 }
 $SIPContact.setInfo()
 }

The example csv file contains this:

John Spencer,,john.spencer@litwareinc.com
Spencer John,Spencer Displayname John,spencer.john@litwareinc.com