Exchange Online - Extract user's contacts with PS

New Contributor

Hi all,


I have spent a fair amount of time trying to find a Powershell script enabling me to extract the contacts of an O365 Exchange account to a local file. It has proven to be somewhat of a challenge.


I found this script, which upon first observation should be able to produce what I want, but the script doesn't work, it fails indicating an Autodiscover error.


C:\Scripts\EXOGetContacts.ps1 : The Autodiscover service returned an error.
Au caractère Ligne:1 : 1
+ .\EXOGetContacts.ps1
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [EXOGetContacts.ps1], AutodiscoverRemoteException
    + FullyQualifiedErrorId : AutodiscoverRemoteException,EXOGetContacts.ps1


Does anyone have any suggestions, either for the above error, or for an alternative methode to extract contacts using Powershell?


Much appreciated, kind regards.

2 Replies
best response confirmed by Jaap Hoetmer (New Contributor)

The script seems to have some undefined variables, and thus fails to connect. You can put something like this:


$exchangeService.Url = ""


I'd recommend using Glen's EWSContacts module for any Contacts related operations:

Hi Vasil,


Thanks for your suggestion, it turned out to be a problem with autodiscovery not finding the correct URL, the suggestion you gave by bypassing autodiscovery works. I'll try to understand why it doesn't work using Autodiscovery.


I'll also give Glen's EWSContacts script a try.


Much appreciated, kind regards,