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 *

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: