Glen Munro blogs about Lync, Microsoft and Cisco products used in his capacity as a Network Administrator for Prairie South School division. Look for him on social media sites as "GM_Pentaxfan"
Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts
Thursday, April 2, 2015
Removing a Lync Contact using Powershell and XML
Back in February I posted about adding contacts to Lync Groups.
However, what happens when you spell the contact address wrong and you just imported that into your 1000+ clients contact list...
Well, you need to find a way to remove the contact from the XML file.
I could have restored the backup files to the user accounts... but didn't think of that until I got this solution working. *
After trying to create an XML script tath use the same script in the previous post, but this time we will replace the offending string with blanks.
Add this to the Configurable Variables section
#Delete this line from XML
$Variable = @'
<Contact Buddy="contact@domain.com" SubscribePresence="1" Groups="1 20" />
'@
$CommonContact = "contact@domain.com" # The one that is spelled wrong.
In the Process-Contacts Function,
Change If ($ContactsToAdd) to If ($ContactsToAdd)
Remove the $ContactsToAdd section and replace it with.
$DeleteRecord = (Get-Content "$WorkingFolder\DocItemSet.xml") |
ForEach-Object {$_ -replace $Variable, ""} |
Set-Content "$WorkingFolder\DocItemSet.xml"
* This does remove the contact from the user's visual list of contacts. However, when the user's contact info is exported, the old contact is still there just not listed in any groups which is why it doesn't appear in the client.
In short, double check spelling and try it on a test account.
To change the script from all users to 1 users change...
$AllSipAddresses = Get-CsUser -Identity lyncroom@domain.com -Filter {Enabled -eq $True} | Select SipAddress | %{$_.SipAddress.Replace('sip:','')}
Original Post about adding groups found here on Roland Paix's IT Blog
More on the custom Lync rooms found here.
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
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 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.
Subscribe to:
Posts (Atom)