Extracting Lync Contacts from XML export

By | 2017-12-07T10:22:41+00:00 January 16th, 2015|Skype|0 Comments

Whilst a customer’s site they wanted to be able to create an export of all users Lync contacts and be able to provide a list to users of their contacts.

Below is the powershell I created to extract the information from the XML export file, the end result was to create a CSV file that had a field of SIP address (which matched their email address) and a field that had all the user’s contacts sip addresses listed, the customer would then use the CSV to provide the information to the user.

Values are hard coded as this was designed to fulfil a specific need but could be converted to a function accepting filenames as inputs.

 

Hope it helps

 

[code]
# Lync 2010 export using dbimpexp
# .Dbimpexp.exe /hrxmlfile:filename.xml /restype:user /sqlserver:SQLserverinstance
# Lync 2013 export using powershell
# Export-CsUserData -LegacyFormat -PoolFqdn pool.fqdn -FileName filename.xml

# Amend import file name
[xml]$contact = Get-Content d:filename.xml

#output file
$outputfile = “d:Contacts.csv”

$output = $contact.HomedResources.homedresource
# Declare an array to collect our result objects
$resultsarray =@()
foreach ($user in $output)
{
$contactlist = “”
$contactObject = new-object PSObject
$sipaddress=$user.userathost
$user_contacts=$user.contacts.contact
# Here we search the contact list and add the contacts to a new variable, separating each with a comma

foreach($buddy in $user_contacts)
{$contactlist = $contactlist + $buddy.buddy+”,”}
# Here we now add the users information to the CSV file, we’re just adding their sip address and contacts in this process
$contactObject | add-member -membertype NoteProperty -name “SIP Address” -Value $sipaddress
$contactObject | add-member -membertype NoteProperty -name “Contacts” -Value $contactlist
$resultsarray += $contactObject
}

#Now we’re saving the information to a single CSV file but you could save it individually.
$resultsarray| Export-csv $outputfile -notypeinformation
[/code]

Leave A Comment

like what you see? 

Sign-up to our newsletter and never miss out on the latest blogs, events and tech news from the world of risual
SUBSCRIBE!
Give it a try, you can unsubscribe anytime.