Use a PowerShell function to get AutoDiscover XML

by Bharat Suneja

If you manage Exchange or support Exchange Online users, you may need to retrieve the AutoDiscover XML response. You can use the Test E-mail AutoConfiguration option in Outlook or the AutoDiscover tests in Microsoft Remote Connectivity Analyzer to retrieve the AutoDiscover response. The good news is you can also use a PowerShell one-liner or function to retrieve it.

Here’s a one-liner that uses the Outlook.Application COM object. It requires Outlook.

(New-Object -comobject Outlook.Application).session.autodiscoverxml

Add Get-AutoDiscoverXML function to your PowerShell profile or script

You can also add it to your PowerShell profile and invoke it using a shorter or easier to remember function name at any time. Add the following function to your PowerShell profile.

Function Get-AutoDiscoverXML {
$OutlookApplication = New-Object -comobject Outlook.Application
$outlookApplication.Session.AutoDiscoverXML
}

Now start PowerShell and you can retrieve the AutoDiscover response at any time using Get-AutoDiscoverXML.

Retrieving AutoDiscover XML as an XML document

When you use the above code, you get the AutoDiscover XML response as a string. It’s a lengthy string that you can paste in a text editor (Notepad++ is much better suited to scripting/writing and reviewing code and XML docs like this AutoDiscover response). In PowerShell, you’ll see the response quickly fill up your screen and the formatting isn’t conducive to reading. Of course, if you know the AutoDiscover XML schema and what you’re looking for, it may work for you.

If you’re used to PowerShell objects, tab completion and tabbing through an object’s properties, you may find the following method useful. It retrieves the AutoDiscover response as an XML doc.

$autodiscoverxml = [xml](New-Object -comobject Outlook.Application).session.autodiscoverxml

After retrieving the XML doc, try tabbing through it. For example:

$autodiscoverxml.Autodiscover.Response.Account.AlternativeMailbox
$autodiscoverxml.Autodiscover.Response.Account.Protocol
$autodiscoverxml.Autodiscover.Response.Account.Protocol | ? {$_.type -eq “mapihttp”} | fl *

{ 1 comment… read it below or add one }

Eriq VanBibber December 21, 2017 at 3:51 pm

Wanted to let you and future readers know about a free tool that can be used to retrieve the AutoDiscover XML result from any server (that supports such).

Priasoft (of which I represent) has produced this tool for our own support and troubleshooting needs, but found it valuable to most that are faced with tracking down issues with AutoD.

The tool does not need outlook installed (great for running on a server in a pinch) and has a drop-down for choosing the version of outlook to send to the server (good for getting mapiHTTP info which is version dependent).

It follows the same auto-resolve pattern as outlook and has all the current overrides (like no SCP or no SRV) in checkboxes so they can easily be turned on/off for testing.

Hopefully it finds use and helps others as it has for us.

It can be found here: https://www.priasoft.com/autodiscover-testing-tool/

Reply

Leave a Comment

Previous post:

Next post: