Friday 11 April 2014

Automatically Populate Contacts For All Lync 2013 Users

**** UPDATE January 2015: Apologies to anyone who has been trying unsuccessfully to use the script with Exchange 2013.  It only works when contacts are stored in Lync, not in the Exchange 2013 unified contact store.  I'm not sure when I'll have time to have a look at fixing it. ****

**** UPDATE:  v1.1 of the script fixes a problem where the script would crash when attempting to update a Lync account that hadn't been logged onto before (and had no user data).  The script skips these accounts and will process them as normal once they've been logged onto at least once. ****

As a follow-up to my previous post Automatically Populate Contacts For All Lync Users which was written for Lync 2010, I've rewritten the script for Lync 2013. As per the Lync 2010 script, these were the criteria:
  • 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
The Lync 2010 version of the script relied on the dbimpexp.exe tool but this functionality has been moved into Lync 2013 PowerShell commands (*-csuserdata).  The 2013 script is cleaner in the way it manipulates the XML.

Instructions for deploying the script are included in the script. If you want to run it as a scheduled task, follow the instructions in the Lync 2010 blog.

The script can be downloaded here:

UpdateLync2013Contacts.ps1 (zipped)


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.

22 comments:

  1. Hey man! Great script! I have Lync Server 2013 up and running, and struggling to get all contacts to everyone! This will sure help a lot! Well, nothing is perfect and maybe you can help me some more!

    Error in foreach that it cannot index into a null array...

    C:\UpdateLync2013Contacts.ps1:180 caractere:22
    + $ContactsToAdd | foreach{
    + ~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [ForEach-Object], RuntimeE
    xception
    + FullyQualifiedErrorId : InvokeMethodOnNull,Microsoft.PowerShell.Commands
    .ForEachObjectCommand


    Any thounghts on how to solve this problem?

    ReplyDelete
    Replies
    1. I'm not sure what's happened there. There's logic in the script to avoid null arrays.

      Are you running the script on a non-English language server, Italian perhaps? I don't know what effect that would have.

      Delete
    2. Yes! I´m running on a PT-BR (Portuguese-Brasil) 2008 R2 server, and Lync 2013 Standard PT-BR also.
      This link(on your script), http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp is not working anymore... anything with that?

      Delete
    3. The link is just an XML schema reference, not a website URL so that's OK.

      I suspect the problem is due to the different system language but I've no experience with PowerShell in different languages. Maybe you could set the culture of the thread to en-us (http://occasionalutility.blogspot.com.au/2014/03/everyday-powershell-part-17-using-new.html) but I don't have too much hope for that, sorry!

      Delete
    4. well, lets study about this! :) Anyway, thanks a lot, i´ve fav´d your blog, i´ll keep track of your posts here, really good content! :) Any news i stop by and post it here!

      Delete
    5. I've updated the blog/script/link with v1.1 that fixes the problem. Sorry I didn't spot it the first time!

      Delete
    6. Hey man... THANKS A LOT! Where do i sent a cold beer?!

      Delete
    7. Works very Well! Thank you again! :D

      Delete
  2. Just noticed, this script does not work in Lync 2010 Clients... is that correct? I have mixed clients on my domain, some 2010 and some 2013 :(

    Maybe the 2010 version will work! :D

    ReplyDelete
    Replies
    1. The client version is irrelevant as it's a server-side script. This version of the script will only run on Lync Server 2013 though.

      Delete
  3. And i just remembered, i havelync 2013 server installed, i don´t have dbimpexp.exe installed!! :P lol!

    ReplyDelete
  4. Hi Roland, great script. However I am also getting the same error as the other poster (although in English) and I am using a EN-US environment, server 2012, Lync 2013...any suggestions? thanks.:

    Error in foreach that it cannot index into a null array...

    C:\UpdateLync2013Contacts.ps1:180 caractere:22
    + $ContactsToAdd | foreach{
    + ~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [ForEach-Object], RuntimeE
    xception
    + FullyQualifiedErrorId : InvokeMethodOnNull,Microsoft.PowerShell.Commands
    .ForEachObjectCommand

    ReplyDelete
    Replies
    1. Ah, OK, I've got it now. It's failing on accounts that have never been logged onto because there's nothing there yet to update. I'll add a workaround and update the script/blog.

      Delete
    2. Blog/script/link have been updated with v1.1.

      Delete
  5. Roland, your a rock star! I was so hoping you would get to my post tonight and you came through. The script now works brilliantly, tested and confirmed. Thank you so much...Great Job!

    ReplyDelete
  6. Very awesome script but for some reason I can't get it out of test mode?

    ReplyDelete
    Replies
    1. Make sure you hash out the line rather than setting the variable to $false.

      RIGHT:
      #$TestingMode = $True

      WRONG:
      $TestingMode = $False

      The script is looking for the presence of the variable rather than if it's true or false. I don't know why I chose to do it that way, it confuses me sometimes!

      Delete
    2. It still is saying

      Test mode enabled; no updates performed

      Delete
    3. Got it figured out. Once again great script:)

      Delete
  7. Thanks, just tested this in an enterprise pool.
    To get the poolname type:
    Get-CsService -UserDatabase

    Used this line :
    $EPSQLServer = "UserDatabase:sql01"

    ReplyDelete
  8. Due to spam I'm stopping comments on this page for a while.

    ReplyDelete