Tuesday, October 17, 2017

Export Contacts from a Mailbox Contacts Folder or Public Folder to a CSV file using EWS and REST

As I had a few questions about exporting contacts to CSV from both Mailbox and Public folders I've added some new functions to the my EWS contacts module to make this easier.  I've added to new cmdlets the first is

Export-ContactsFolderToCSV

This will export a contacts folder to CSV's either the default Contacts Folder in a Mailbox or a secondary Contacts folder if you enter in the FolderPath eg to export the Default contacts Folder use

Export-ContactsFolderToCSV - MailboxName user@domain.com -FileName c:\exports\contacts.csv

To export a Secondary Contacts Folder use

Export-ContactsFolderToCSV - MailboxName user@domain.com -FileName c:\exports\contacts.csv -Folder \Contacts\SecondContactsFolder

Export-PublicFolderContactsFolderToCSV

This will export a Public Contacts Folder to a CSV file to use this use

Export-PublicFolderContactsFolderToCSV -MailboxName mailbox@domain.com -FileName c:\exports\PublicFolderexport.csv -PublicFolderPath \folder\folder2\contacts

The EWS Contacts Module is available on GitHub here https://github.com/gscales/Powershell-Scripts/blob/master/EWSContacts/EWSContactFunctions.ps1

I've also added some code to my Exch-REST module to allow export of a Contacts Folder using the new REST API on Office365 and Exchange 2016. To use this you need version 2.4 of the module from the PowershellGallery https://www.powershellgallery.com/packages/Exch-Rest then use

Export-ContactFolderToCSV -MailboxName tmpcontact@domain.com -AccessToken $AccessToken -FileName c:\exports\filename.csv




No comments: