SOLVED

Exchange Online - Extract user's contacts with PS

%3CLINGO-SUB%20id%3D%22lingo-sub-218380%22%20slang%3D%22en-US%22%3EExchange%20Online%20-%20Extract%20user's%20contacts%20with%20PS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-218380%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20spent%20a%20fair%20amount%20of%20time%20trying%20to%20find%20a%20Powershell%20script%20enabling%20me%20to%20extract%20the%20contacts%20of%20an%20O365%20Exchange%20account%20to%20a%20local%20file.%20It%20has%20proven%20to%20be%20somewhat%20of%20a%20challenge.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20found%20this%20script%20%3CA%20href%3D%22https%3A%2F%2Fgallery.technet.microsoft.com%2Foffice%2FHow-to-export-a-mailboxs-2dd7247a%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgallery.technet.microsoft.com%2Foffice%2FHow-to-export-a-mailboxs-2dd7247a%3C%2FA%3E%2C%20which%20upon%20first%20observation%20should%20be%20able%20to%20produce%20what%20I%20want%2C%20but%20the%20script%20doesn't%20work%2C%20it%20fails%20indicating%20an%20Autodiscover%20error.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EC%3A%5CScripts%5CEXOGetContacts.ps1%20%3A%20The%20Autodiscover%20service%20returned%20an%20error.%3CBR%20%2F%3EAu%20caract%C3%A8re%20Ligne%3A1%20%3A%201%3CBR%20%2F%3E%2B%20.%5CEXOGetContacts.ps1%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3A%20NotSpecified%3A%20(%3A)%20%5BEXOGetContacts.ps1%5D%2C%20AutodiscoverRemoteException%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20FullyQualifiedErrorId%20%3A%20AutodiscoverRemoteException%2CEXOGetContacts.ps1%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20anyone%20have%20any%20suggestions%2C%20either%20for%20the%20above%20error%2C%20or%20for%20an%20alternative%20methode%20to%20extract%20contacts%20using%20Powershell%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMuch%20appreciated%2C%20kind%20regards.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-218380%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExchange%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-218821%22%20slang%3D%22en-US%22%3ERe%3A%20Exchange%20Online%20-%20Extract%20user's%20contacts%20with%20PS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-218821%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Vasil%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20your%20suggestion%2C%20it%20turned%20out%20to%20be%20a%20problem%20with%20autodiscovery%20not%20finding%20the%20correct%20URL%2C%20the%20suggestion%20you%20gave%20by%20bypassing%20autodiscovery%20works.%20I'll%20try%20to%20understand%20why%20it%20doesn't%20work%20using%20Autodiscovery.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'll%20also%20give%20Glen's%20EWSContacts%20script%20a%20try.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMuch%20appreciated%2C%20kind%20regards%2C%3C%2FP%3E%3CP%3EJaap%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-218475%22%20slang%3D%22en-US%22%3ERe%3A%20Exchange%20Online%20-%20Extract%20user's%20contacts%20with%20PS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-218475%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20script%20seems%20to%20have%20some%20undefined%20variables%2C%20and%20thus%20fails%20to%20connect.%20You%20can%20put%20something%20like%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24exchangeService.Url%20%3D%20%22%3CA%20href%3D%22https%3A%2F%2Foutlook.office365.com%2FEWS%2FExchange.asmx%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Foutlook.office365.com%2FEWS%2FExchange.asmx%3C%2FA%3E%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI'd%20recommend%20using%20Glen's%20EWSContacts%20module%20for%20any%20Contacts%20related%20operations%3A%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fgscales%2FPowershell-Scripts%2Ftree%2Fmaster%2FEWSContacts%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fgscales%2FPowershell-Scripts%2Ftree%2Fmaster%2FEWSContacts%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
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 https://gallery.technet.microsoft.com/office/How-to-export-a-mailboxs-2dd7247a, 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
Highlighted
Best Response confirmed by Jaap Hoetmer (New Contributor)
Solution

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

 

$exchangeService.Url = "https://outlook.office365.com/EWS/Exchange.asmx"

 

I'd recommend using Glen's EWSContacts module for any Contacts related operations: https://github.com/gscales/Powershell-Scripts/tree/master/EWSContacts

Highlighted

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,

Jaap