Thursday, 20 December 2012

Automatically Populate Contacts For All Lync Users

*** Update: This script is for Lync 2010. If you're looking for the Lync 2013 version please go to Automatically Populate Contacts For All Lync 2013 Users ***

I recently found myself looking for a way to populate all Lync users' address books with all Lync users.  This came about because open federation was in use and security requirements dictated that only users in people's contacts lists could see presence information.  I needed a way to ensure that all Lync users in the organisation were in everyone's Lync contacts.

After enabling privacy mode (http://technet.microsoft.com/en-us/library/gg399028.aspx) I tried adding a group containing all users to my Lync contacts but this didn't work. The context of the contact in this case is the group rather than the users in the group so nobody could see my presence (they have to be users directly in my contacts list to be able to see my presence).

So I googled around a bit and found a few scripts that people have created to add contacts such as this one by Jeff Guillet:

http://www.expta.com/2011/01/introducing-lyncaddcontacts.html

It didn't quite do what I wanted it to and it's written in vbscript rather than powershell so I decided to write my own.

Here's what I set out to achieve:

  • A script that can be run as a scheduled task or manually
  • Full automation so that new Lync users automatically:
    • are added to everyone's contacts
    • have their address book fully populated
  • No reliance on a dedicated template Lync user for exporting contacts
  • No interference with existing contacts/groups, just adding the missing ones
  • An up-to-date backup of all users' homed resource data
  • The ability to exclude particular users from receiving all contacts
  • The ability to exclude particular users from being added to all address books
  • The ability to define a list of particular users to be added to all address books (instead of adding all Lync users)
  • A testing mode so that results can be checked without making any changes to Lync
  • Logging with email notifications
  • No notifications or popups in clients when contacts are added
I wrote the script in PowerShell 2.0 as that's what is currently running on my Lync 2010 server.  The script is suitable for smaller environments but could run in larger ones if you're patient and take into account address book limitations.  I'd like to rewrite the script in PowerShell 3.0 sometime and make use of workflows which would speed up the processing a lot.

The script uses the Lync tool DBImpExp.exe to export each users' homed resource data, compare it to a list of users that should be in everyone's address book and update each address book with the missing contacts.

To use the script, download it to a front end server to C:\Scripts\ (or wherever you prefer).  Edit the script and customise the variables per your requirements.

The account used to run the script must be a member of the RTCUniversalServerAdmins group and must have write permission to your working folder.

To run the script as a scheduled task I strongly recommend you create and use a dedicated service account.  You must allow the account to log on as a batch job on the Lync front end server.

You could use the following task settings:

Name:  Update Lync Contacts
Description:  This script updates all Lync users' address books with all Lync users.
Trigger:  Daily @5am
Action:  Start a program
Program:  PowerShell.exe
Arguments:  -NonInteractive -WindowStyle Hidden -command "& 'C:\Scripts\UpdateLyncContacts.ps1'"

Once the scheduled task is created open it and set:

<General> Security options:
- Set it to run using your dedicated service account
- Run whether user is logged on or not
- Run with highest privileges

<Settings>:
- Allow task to be run on demand
- Stop the task if it runs longer than: 1 hour

If you download and use the script please ensure that it is suitable and configured correctly for your environment.  I'd love to know if you use it so please leave me a comment if you do.  Also note that I accept no liability or responsibility if it doesn't work as expected!

The script can be downloaded here:




This post in its entirety is the copyright of Roland Paix. I don't mind if you link to it but if you copy any of the content you must provide a link to the post and credit me appropriately.

5 comments:

  1. any luck getting this to work on 2013

    ReplyDelete
  2. Haven't had a chance to try it yet but I'll update the blog when I do.

    ReplyDelete
  3. Doesn't seem to have DBImpExp.exe in 2013. Any script for 2013?
    Thanks

    ReplyDelete
  4. I've finally had time to rewrite the script for Lync 2013 and it can be found here: http://rp-it.blogspot.com/2014/02/automatically-populate-contacts-for-all-lync-2013-users.html.

    ReplyDelete
  5. Hello, I just run your script on my corporate server.

    Firstly Thank you roland for this script, It works great (no problem on my server in french).
    In an other hand, I like to know if there would be an opportunity to inject a contact list listed with different groups:
    For example:
    Group 1: Name: Computer pole: xxxx@xxxx.com; yyyy@xxx.com ...
    Group 2: Name: Human Resources: xxxx@xxxx.com; zzzz@zzzz.com ...
    etc ...
    Thanks

    ReplyDelete