I read this recent post at Jim McBee’s Mostly Exchange blog about how to specify a domain controller when issuing Exchange Management Shell commands. After battling the Blogger comments system for a few minutes I gave up and decided to write this blog post instead.

Jim notes that the shell will generally choose the closest domain controller, which is not always the most appropriate one depending on the administrative tasks you are planning to execute.

Jim points out that you can add the -DomainController argument to any EMS cmdlet, which will resolve the issue for that specific command.  However there are two other ways to address this issue.

One way is to modify the $AdminSessionADSettings settings, which can be seen from the shell.

[PS] C:>$AdminSessionADSettings

ViewEntireForest              : False
DefaultScope                  : contoso.com
PreferredGlobalCatalog        :
ConfigurationDomainController : exch2007.contoso.com
PreferredDomainControllers    : {}

Note these two settings:

  • ConfigurationDomainController – lets you hard code a DC to use for shell cmdlets
  • PreferredDomainControllers – lets you specify one or more preferred DC’s for shell cmdlets to use. If a domain is specified that is not served by one of these preferred DC’s one will be chosen automatically.

Modifying the settings is simple.

[PS] C:>$AdminSessionADSettings.ConfigurationDomainController = 'dc1.contoso.com'
[PS] C:>$AdminSessionADSettings.PreferredDomainControllers = 'dc1.contoso.com','dc2.contoso.com'

Any DC that you specify here must be valid or an error will appear and the change rejected.

Modifying $AdminSessionADSettings applies to the current session only. To make these changes apply to all EMC sessions that the administrator launches you must edit the BinExchange.ps1 file in the Exchange Server installation folder. Look for this line in the file:

$global:AdminSessionADSettings.ViewEntireForest = $false

Then simply append any additional settings after it.

$global:AdminSessionADSettings.ViewEntireForest = $false
$global:AdminSessionADSettings.ConfigurationDomainController = 'dc1.contoso.com'

This change will then take affect for all future Exchange Management Shell sessions on that server.

About the Author

Paul Cunningham

Paul is a former Microsoft MVP for Office Apps and Services. He works as a consultant, writer, and trainer specializing in Office 365 and Exchange Server. Paul no longer writes for Practical365.com.


  1. Jimmy Bowers

    I demoted an old 2003 DC and now it is just a member server, upgraded the function level to 2008 and now my exchange server does not see any DCs.
    I ran the following command and it failed with any Domain Controller and they all have Global Catalogs;
    $AdminSessionADSettings.PrefferedDomainController =
    Can you help me please?

  2. Server System Engineer


    I need to migrate all of my Exchange Server 2007 from one AD site into another one within the same AD domain, so shall I do the following Registry changes first:

    Key: SystemCurrentControlSetServicesNetlogonParameters
    Name: New-AD-SiteName
    Type: REG_SZ

    followed by the below Powershell command:

    Set-ExchangeServer -Identity PRODExcMBX1 -StaticConfigDomainController PRODDC1 -StaticGlobalCatalogs PRODDC1
    Set-ExchangeServer -Identity PRODExcMBX1 -StaticConfigDomainController PRODDC2 -StaticGlobalCatalogs PRODDC2

  3. Martin Gauvreau

    Thanks Paul. You saved my life, and my job!
    I accidently deleted some important VMs files from our ESX Storage. Since then, our DC is down and therefore Exchange wasn’t working.


Leave a Reply