Sunday, March 3, 2013

Exchange 2013 Maintenance Mode

UPDATE (11/03/2013): change made to the process of emptying the queues (please see below)

With Exchange 2013, Microsoft introduced many new features to further improve Database Availability Groups, or DAGs. One of these new features is called Maintenance Mode and it enables administrators to designate a server as in-service or out-of-service by using the Set-ServerComponentState cmdlet. With Exchange 2010, administrators had to use the StartDagServerMaintenance.ps1 script or manually prepare a DAG member for maintenance.
As with the script, Maintenance Mode is used to tell Exchange that a particular server should not be available to service clients. In a mailbox server, an administrator will typically perform a switchover to another server (if the server to be put in maintenance mode is hosting active database copies) and then use the Set-MailboxServer and Set-ServerComponentState cmdlet to put it into maintenance mode, preventing the active copies from being activated and disabling the Transport services.
Enabling Maintenance Mode on a Mailbox server role is straightforward. Let’s consider mailbox server MBX1. Before you can disable the Transport service, all active queues need to be drained first:
Set-ServerComponentState MBX1 -Component HubTransport -State Draining -Requester Maintenance

If the server is part of a DAG, you must run these cmdlets to switchover any active databases currently mounted on the server and prevent those copies from being activated:
Suspend-ClusterNode MBX1

Set-MailboxServer MBX1 -DatabaseCopyActivationDisabledAndMoveNow $True

Set-MailboxServer MBX1 -DatabaseCopyAutoActivationPolicy Blocked

Once the queues are empty, you can disable all components on the server:
Set-ServerComponentState MBX1 -Component ServerWideOffline -State Inactive -Requester Maintenance

UPDATE: if you script the process and use the Get-Queue cmdlet to check how many messages are still in all the queues of the server you are placing in maintenance mode, the script might take a long time to pass this stage because of the Poison and Shadow Redundancy queues... There are two alternatives. One is to update the Get-Queue cmdlet to exclude these queues from your script:

Get-Queue -Server MBX1 | ? {$_.Identity -notmatch "Poison" -AND $_.Identity -notmatch "Shadow"}

The other option is to use the Redirect-Message cmdlet to drain active messages from all the delivery queues on the server and transfer those messages to another Mailbox server:

Redirect-Message -Server MBX1 -Target MBX2

When a message queue is drained, the active messages in the queues on the source Mailbox server are routed to the target Mailbox server. After the messages are received and queued by the target Mailbox server, the messages are made redundant. Please also note that:
• Only active messages are drained. Shadow queues aren't drained;
• Messages in the poison message queue aren't drained;
• The source server won't accept new messages while the queues are drained.


To take MBX1 out of Maintenance Mode all you have to do is reverse these actions. First, reactive all components:
Set-ServerComponentState MBX1 -Component ServerWideOffline -State Active -Requester Maintenance

If the server is part of a DAG, resume the cluster node and remove the restriction on the database copies:
Resume-ClusterNode MBX1

Set-MailboxServer MBX1 -DatabaseCopyActivationDisabledAndMoveNow $False

Set-MailboxServer MBX1 -DatabaseCopyAutoActivationPolicy Unrestricted

And finally resume the transport queues:
Set-ServerComponentState MBX1 -Component HubTransport -State Active -Requester Maintenance


  1. Hi, take a look at and the comments from Brian.

    You don't need to drain the queues; if you do - definitely excluded the poison queue.

    Redirecting the messages also works (and from experience better than suspending them) >



    1. Hi Michael,

      Thank you very much for your comment. It is really good to know that, thanks for sharing!
      I have updated the post and mentioned your blog and Brian’s as the sources.

      Best regards, Nuno

  2. Thanks, useful info. However, saying that " Microsoft introduced many new features to further improve .. DAGs. One of these new features is called Maintenance Mode" seems a little like 'sucking up to MS'. I think calling 'improvement' a removal of one line built-in script and replacing it with a whole page of rather convoluted cmdlets give a word 'improvement' a new meaning.

    1. Thanks!

      That's a fair point. However, that script also had its problems/limitations... I agree that it takes work to do all of this but it can be easily scripted as well :)