Controlling the behavior of Outlook AutoDiscover using the registry is not a new idea. Indeed, it has been around almost as long as AutoDiscover itself—perhaps longer.

If you are unfamiliar with the technique, essentially what we can do is tell Outlook to ignore, or only use, a certain part of the AutoDiscover process. We can use this to good effect in Active Directory environments where an on-premises Exchange environment still exists, but where you may wish to configure an email profile outside of that.

AutoDiscover can use something called Service Connection Point (SCP), which can interrupt or take precedence over externally published DNS information. This is especially true when an organization may be switching from a local Exchange environment to Office 365.

In addition to this, which you can have a relative amount of control over, another situation may arise that requires you to override the AutoDiscover process manually. I speak of course of the externally hosted website.

This situation is relevant for at least two of my clients, one using Office 365, the other still using an Exchange 2010 environment, and I have no reason to think I am alone in this.

The scenario is that the web server a client has their public website running on also accepts IMAP connections. When this is true, and you attempt to AutoDiscover an Outlook account to your Exchange Server, AutoDiscover will find the IMAP service at the root of the domain. It will then attempt to configure Outlook to talk to that instead of moving on to talk to your Exchange Server.

The solution for this is to use the registry to control Outlook's behavior, and the method I have used is to set the PreferLocalXML DWORD entry. Configuring this requires setting at least two registry entries and creating an XML file, which has to contain the AutoDiscover URL for that specific domain.

For example if your domain was using Office 365, your XML may look like this:

<?xml version="1.0" encoding="utf-8" ?>
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
  <Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a">
    <Account>
      <AccountType>email</AccountType>
      <Action>redirectUrl</Action>
      <RedirectUrl>https://autodiscover.mydomain.com/autodiscover/autodiscover.xml</RedirectUrl>
    </Account>
  </Response>
</Autodiscover>

Or for another domain name, it may look like this:

<?xml version="1.0" encoding="utf-8" ?>
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
  <Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a">
    <Account>
      <AccountType>email</AccountType>
      <Action>redirectUrl</Action>
      <RedirectUrl>https://autodiscover.otherdomain.co.uk/autodiscover/autodiscover.xml</RedirectUrl>
    </Account>
  </Response>
</Autodiscover>

Never one to shy away from the chance to automate something, I created a small script to do this for me. The script takes input in the form of a domain name, configures the PreferLocalXML DWORD, the REG_SZ (string) for the domain name, and sets up the XML file.

It also then sets up the other registry entries and disables the ones we do not want to use, leaving only PreferLocalXML, HTTPRedirect, and HTTPSAutoDiscoverDomain enabled.

Configure AutoDiscover in the registry

Configure AutoDiscover in the registry

This script runs in the logged-on user's context and is per user. If you have multiple people sharing the same computer, you would need to run it for all of them. However, it will not recreate the XML file if it is already present.

The last thing to mention is the path where these registry edits occur. This relates to the version of Office installed on your computer.

Using a query, we can determine all the versions installed based on their version number. Then we select the newest version and make our AutoDiscover edits for that version only.

Of course, making a few registry edits is trivial, and even creating an XML file would take a few seconds. But using this script allows me to set up the settings quickly and correctly each time with minimal effort.

Subscribe to 4sysops newsletter!

# Prefer Local XML
# Create Reg Entry for Local User and Folder / XML if Needed
$domainName = Read-Host -Prompt "Enter Domain Name"
try{
    $ErrorActionPreference = "STOP"
    $office = Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Office" | sort Name -Descending | where { $_.Name -like "*.0"}
    if(($office | Measure-Object).Count -gt 1)
    {
        $officeVer = $office[0].PSChildName
    }
    else
    {
        $officeVer = $office.PSChildName
    }
    Write-Output "Office Version : $officeVer"
    $regPath = "HKCU:\SOFTWARE\Microsoft\Office\$officeVer\Outlook\AutoDiscover"
    New-ItemProperty $regPath -Name $domainName -PropertyType STRING -Value c:\autodiscover\autodiscover-$domainName.xml | Out-Null
    New-ItemProperty -Path $regPath -Name PreferLocalXML -propertyType DWORD -Value 1 | Out-Null
    New-ItemProperty -Path $regPath -Name ExcludeHttpRedirect -propertyType DWORD -Value 0 | Out-Null
    New-ItemProperty -Path $regPath -Name ExcludeHttpsAutoDiscoverDomain -propertyType DWORD -Value 0 | Out-Null
    New-ItemProperty -Path $regPath -Name ExcludeHttpsRootDomain -propertyType DWORD -Value 1 | Out-Null
    New-ItemProperty -Path $regPath -Name ExcludeScpLookup -propertyType DWORD -Value 1 | Out-Null
    New-ItemProperty -Path $regPath -Name ExcludeSrvRecord -propertyType DWORD -Value 1 | Out-Null
    if(!(Test-Path c:\autodiscover))
    {
        New-Item c:\AutoDiscover -ItemType Directory | Out-Null
        New-Item c:\AutoDiscover\autoDiscover-$domainName.xml -ItemType File | Out-Null
    }

    $xml = "<?xml version=""1.0"" encoding=""utf-8"" ?>
    <Autodiscover xmlns=""http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006"">
      <Response xmlns=""http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a"">
        <Account>
          <AccountType>email</AccountType>
          <Action>redirectUrl</Action>
          <RedirectUrl>https://autodiscover.$domainName/autodiscover/autodiscover.xml</RedirectUrl>
        </Account>
      </Response>
    </Autodiscover>"
    Add-Content c:\AutoDiscover\autoDiscover-$domainName.xml $xml
    Write-Output "Outlook AutoDiscover Manually Configured"
}
catch{
    Write-Output "An Error Occurred"
    $_.exception.Message
}
+1
3 Comments
  1. Darren 2 years ago

    i get this output 

     

    how do i correct the issue ?

     

    Office Version : 16.0
    An Error Occurred
    Cannot find path 'HKCU:\SOFTWARE\Microsoft\Office\16.0\Outlook\AutoDiscover' because it does not exist.

     

     

    0

  2. Adam 1 year ago

    This script is helpful, thank you. 

    For anyone who is migrating to O365, but have yet to cut over DNS records then add the following registry entry in addition to the script edits. 

     

    HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\office\16.0\outlook\autodiscover
    DWORD: ExcludeExplicitO365Endpoint
    Value = 1
    0

  3. Michael 6 months ago

    Verry much thanks, We have switched from 2013 to 2016 and about 4 weeks we cannot work with outlook, because of we working in other AD as the exchange server is located. With your workaround of the local autodiscover.xml all works fine.

    0

Leave a reply

Please enclose code in pre tags

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2021

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account