Extracting Lync Contacts from XML export

Do yo want to export all of your onpremise Lync users? With the below script, you can do that. You will obtain a CSV with all SIP Adrress.

Hope it helps

# 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
 # 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


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s