Import Contacts for Microsoft Lync 2010
Introduction
This script could be used to import custom groups and distribution groups for Microsoft Lync 2010.
Scenarios
In a real world, IT help desks are often required to add dozens of predefined custom groups or distribution groups for Lync clients in different department. It is a time-consuming task for adding predefined custom group or distribution group for each Lync
client.
Prerequisites
Microsoft Lync 2010 SDK Runtime
Microsoft Lync 2010 SDK Runtime must be installed for each desktop. This runtime is included in Microsoft Lync 2010 SDK. You can download this SDK from
Microsoft Download Center. After installing the SDK, you can copy the LyncSdkRedist.msi file from the %ProgramFiles%\Microsoft Lync\SDK\Redist folder to a shared folder which contains
this script.
You may also install Microsoft Lync 2010 SDK Runtime during the preparation of your desktop image which will be used by Microsoft Deployment Toolkit (MDT) or System Center Configurations Manager (SCCM).
Sign in Requirement
User must sign in to Lync client before running this script.
Script
This script contains two advanced functions, Out-OSCLyncContacts and Import-OSCLyncContacts. You can use this script in following ways:
Method 1:
- Download the script and copy it to a shared folder.
- Open the script file with Notepad or any other script editors.
- Scroll down to the end of the script file, and then add the example command which you want to run.
- Save the file then run the script in Windows PowerShell console for each desktop.
Method 2:
- Rename scriptname.ps1 to scriptname.psm1 (PowerShell Module file)
- Run Import-Module cmdlet to import this module file.Import-Module filepath\scriptname.psm1
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
PowerShell
Edit|Remove
powershell
if ($overWriteGroupMember -eq "True") {
$warningMsg = $Messages.OverwriteWarning
$pscmdlet.WriteWarning($warningMsg)
foreach ($contact in $groupObject) {
Try
{
$groupObject.EndRemoveContact($groupObject.BeginRemoveContact($contact,$null,$null))
}
Catch
{
$pscmdlet.WriteError($Error[0])
}
}
} else {
$warningMsg = $Messages.AppendGroupMember
$pscmdlet.WriteWarning($warningMsg)
}
if ($overWriteGroupMember -eq "True") {
$warningMsg = $Messages.OverwriteWarning
$pscmdlet.WriteWarning($warningMsg)
foreach ($contact in $groupObject) {
Try
{
$groupObject.EndRemoveContact($groupObject.BeginRemoveContact($contact,$null,$null))
}
Catch
{
$pscmdlet.WriteError($Error[0])
}
}
} else {
$warningMsg = $Messages.AppendGroupMember
$pscmdlet.WriteWarning($warningMsg)
}
Examples
Example 01: Displays help about Import-OSCLyncContacts
Command: Get-Help Import-OSCLyncContacts -Full
Screenshot:
Example 02: Prepare a .csv file for Import-OSCLyncContacts. One custom group and two distribution groups will be exported. If the target custom group exists, all the contacts will be removed before adding new contacts. This behavior is
controlled by Overwrite parameter.
Command: Out-OSCLyncContacts -FilePath C:\scripts\042\contacts.csv -DistributionGroup "sales","marketing" -CustomGroupContact @{"Custom Group 01"="lauran;guyg"} -Overwrite -Verbose
Screenshot:

Note: You can use alias for finding distribution group. The value of CustomGroupContact parameter is assigned in following form @"CustomGroupName"="alias01;alias02"}
Example 03: Prepare an .xml file for Import-OSCLyncContacts. One custom group and two distribution groups will be exported. If the target custom group exists, all the contacts will be removed before adding new contacts. If the target custom
group exists, only new contacts will be added.
Command: Out-OSCLyncContacts -FilePath C:\scripts\042\contacts.xml -DistributionGroup "sales","marketing" -CustomGroupContact @{"Custom Group 01"="lauran;guyg"} -Verbose
Screenshot:
Example 04: Import custom groups and distribution groups for current user. If the target custom group exists, all the contacts will be removed before adding new contacts.
Command: Import-OSCLyncContacts -FilePath c:\Scripts\042\contacts.csv -Verbose
Screenshot:
Example 05: Import custom groups and distribution groups for current user. If the target custom group exists, only new contacts will be added.
Command: Import-OSCLyncContacts -FilePath c:\Scripts\042\contacts.xml -Verbose
Screenshot:

Additional Resources
Forum Threads: