Friday, February 20, 2015

Bulk Import Custom Contact Groups into Lync User accounts

Was looking for a way to Populate our Lync Room systems into end users Lync Contacts as a group rather than a bunch of individual accounts.  (More on Lync Room Systems here http://bit.ly/netadmlr)

Based on the PowerShell script found below, a new section was created for the Contact Groups.
http://rp-it.blogspot.ca/2014/02/automatically-populate-contacts-for-all-lync-2013-users.html

Rather than repost the entire code, here's the updated sections...
For each Lync group that you want to create I would suggest creating new scripts.

For Individual account testing...

#Old version Enable for All users Disable for individual testing
$AllSipAddresses = Get-CsUser -Filter {Enabled -eq $True} | Select SipAddress | %{$_.SipAddress.Replace('sip:','')}

#GM Added - Enable for individual testing
#$AllSipAddresses = Get-CsUser -Identity lastname.first@domain.com -Filter {Enabled -eq $True} | Select SipAddress | %{$_.SipAddress.Replace('sip:','')}


# Common Contacts - Enable and populate this variable with a set of Lync contacts to distribute to all users instead of distributing all users to all users. Overrides $DontAddUsers.
#$CommonContacts = "lrs1@domain.com","lrs2@domain.com"

To add /verify the Group exists.
$AllContacts = @($SipAddressesToAdd | ?{$_ -ne $User})
    [xml]$XMLFile = Get-Content "$WorkingFolder\DocItemSet.xml"
    $XMLPart = $XMLFile.DocItemSet.DocItem | ?{$_.Name -like "urn:lcd:*"}
    $XMLNode = $XMLPart.Data.HomedResource.Contacts
$XMLNodeGroup = $XMLPart.Data.HomedResource.ContactGroups #GM
    $ExistingContacts = @($XMLNode.Contact | Select -ExpandProperty Buddy)
$ExistingContactGroups = @($XMLNodeGroup.ContactGroup | Select -ExpandProperty DisplayName) #GM
#GM Lync Rooms Contact Group Add
If($ExistingContactGroups){
If($ExistingContactGroups -eq "THluYyBSb29tcw=="){
write-host "`r`nLync Room Group Exists. Nothing changed.`r`n"
}
Else{
write-host "`r`nLync Room Group will be added.`r`n"
[System.XML.XMLLinkedNode]$NewContactGroup = $XMLFile.CreateElement('ContactGroup','http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp')
            $NewContactGroup.SetAttribute('Number','20') #High number so as to not overwrite existing groups.
            $NewContactGroup.SetAttribute('DisplayName','CodeFromXML')
            #Display name in ContactGroups found in XMl file in test account
            #Export-CsUserData -PoolFqdn "lyncserver.domain.com" -UserFilter name@domain.com -FileName "c:\scripts\test.zip"
            $XMLNodeGroup.AppendChild($NewContactGroup)
        }
}
Else{
write-host "`r`nNo existing contact groups found.`r`n"
write-host "`r`nAdding New Contact Group XML Element.`r`n"
[System.XML.XMLLinkedNode]$NewNodeGroup = $XMLFile.CreateElement('ContactGroups','http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp')
            [System.XML.XMLLinkedNode]$NewContactGroup = $XMLFile.CreateElement('ContactGroup','http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp')
            $NewContactGroup.SetAttribute('Number','20') #High number so as to not overwrite existing groups.
            $NewContactGroup.SetAttribute('DisplayName','CodeFromXML')
            $NewNodeGroup.AppendChild($NewContactGroup)
            $XMLCGroup = $XMLPart.Data.HomedResource.Containers
            $XMLPart.Data.HomedResource.InsertBefore($NewNodeGroup,$XMLCGroup)
            $XMLFile.Save("$WorkingFolder\DocItemSet.xml")
            [xml]$XMLFile = Get-Content "$WorkingFolder\DocItemSet.xml"
            $XMLPart = $XMLFile.DocItemSet.DocItem | ?{$_.Name -like "urn:lcd:*"}
            $XMLNode = $XMLPart.Data.HomedResource.Contacts
}
#Back to original code
    Write-Host "`r`nExisting contacts:`r`n" 

Change these lines to include 1 and the group number in the $ContactstoAdd | foreach{} section
$NewContact.SetAttribute('Groups','1 20') 

If you have a large organization, you will need to create a new policy or edit the Global Presence policy.  Once all the Lync users had the Lync Rooms in the list, the "Maximum Followers Reached" error showed up on the Lync Room systems.

A new Presence Policy was created and applied to the Lync Room accounts. The MaxCategorySubcriptions was to 3000 and the error went away.

 Since it was only applied to the Lync Room systems it should not drastically increase the server traffic as compared to applying to all our Lync users.

No comments:

Post a Comment