Using maintenance mode in Exchange Server.

In this article, we will look at how to correctly put an Exchange Server 2019/2016 host into maintenance mode. An Exchange Database Availability Group (DAG) server must be put into maintenance mode if you plan to install updates on the Exchange host (Windows updates or Exchange CU) or perform server hardware platform maintenance. When transferring a server to maintenance mode, you need to transfer active databases from the server and switch the queue to other servers.

Exchange Server has two built-in PowerShell scripts associated with maintenance mode:

  • StartDagServerMaintenance.ps1 - allows you to move active databases, the Primary Active Manager (PAM) dispatcher role to another server and block the reverse migration of mail databases until maintenance is completed;
  • StopDagServerMaintenance.ps1 - Allows you to take the Exchange server out of maintenance mode by performing the reverse procedures.

These scripts are located in the Exchange installation directory in the Scripts folder (CD $ExScripts). The following syntax is used for these scripts:

.\StartDagServerMaintenance.ps1 -ServerName <ServerName> -MoveComment Maintenance -PauseClusterNode
.\StopDagServerMaintenance.ps1 -serverName <ServerName>
These scripts help automate some of the operations. But in most cases, Exchange administrators prefer to perform all the steps to bring the server into maintenance mode manually.

Below is an example of a ready-made PowerShell script that can be used to put Exchange into maintenance mode. The commands must be run on a computer with the Exchange Management Shell and the RSAT-Clustering module installed:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
Import-Module FailoverClusters

 Or you can connect to the Exchange server remotely using PowerShell:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://msk-mbx1.winitpro.ru/PowerShell/ -Authentication Kerberos -Credential (Get-Credential) 

Import-PSSession $Session

Set the names of the Exchange servers:

# server that is put into maintenance mode
$maintance_srv = "msk-mbx1.site.io"
# target server to transfer queues to
$target_srv = "msk-mbx2.site.io"
# Disable the HubTransport component on the server and put it into Draining mode
Set-ServerComponentState $maintance_srv –Component HubTransport –State Draining –Requester Maintenance
Restart-Service MSExchangeTransport
# You can check that the HubTransport status has changed to Draining
Get-ServerComponentState -Identity $maintance_srv -Component Hubtransport 

If you run the command now Get-ServerComponentState -Identity $maintance_srv , then all Exchnage components (except Monitoring and RecoveryActionsEnabled) should be in the Incative state.

# Now you need to move the message queues to another server
Redirect-Message -Server $maintance_srv -Target $target_srv
# Check that the queues have cleared with the command:
Get-Queue
# Pause the cluster node, which will move the Primary Active Manager (PAM) role to another server in the DAG
Suspend-ClusterNode –Name $maintance_srv
# Transfer of all mounted copies of mail databases to other servers
Set-MailboxServer $maintance_srv –DatabaseCopyActivationDisabledAndMoveNow $true
# Disable activation of mail databases on the server
Set-MailboxServer $maintance_srv –DatabaseCopyAutoActivationPolicy Blocked 
Wait for the mail databases to switch (it will take a few minutes). Make sure the list of mounted databases on the server is empty:

Get-MailboxDatabaseCopyStatus -Server $maintance_srv | where {$_.Status -like "Mounted"}
# Putting Exchange Components in Maintenance Mode
Set-ServerComponentState $maintance_srv –Component ServerWideOffline –State InActive –Requester Maintenance
# Check if the server is in maintenance mode:
Get-ServerComponentState -Identity $maintance_srv -Component ServerWideOffline
Get-MailboxDatabaseCopyStatus 
Now you can complete the maintenance procedures for the Exchange host that you need. After finishing work with the server, you need to perform the reverse procedure for removing Exchange from maintenance mode:

Set-ServerComponentState $maintance_srv –Component ServerWideOffline –State Active –Requester Maintenance
# The status can be checked like this (should become Active):
Get-ServerComponentState $maintance_srv -Component ServerWideOffline

Resume-ClusterNode –Name $maintance_srv
Set-MailboxServer $maintance_srv –DatabaseCopyAutoActivationPolicy Unrestricted
Set-MailboxServer $maintance_srv –DatabaseCopyActivationDisabledAndMoveNow $false
Set-ServerComponentState $maintance_srv –Component HubTransport –State Active –Requester Maintenance

Check the Exchange Server status with:

Test-ServiceHealth $maintance_srv

Distribute mail databases across DAG servers according to your preferences using the RedistributeActiveDatabases.ps1 script:

cd $exscripts
.\RedistributeActiveDatabases.ps1 -DagName msk-dag –BalanceDbsByActivationPreference

If you need to move all active copies of mail databases from one server to another, run:

  • Move-ActiveMailboxDatabase -Server $target_srv -ActivateOnServer $maintance_srv -Confirm:$false

Perform a MAPI availability check:

Test-MAPIConnectivity -Server $maintance_srv
Check the status of the databases and replication in the DAG:

Get-MailboxDatabaseCopyStatus
Test-ReplicationHealth -DatabaseAvailabilityGroup

Отправить комментарий

Добавлять новые комментарии запрещено.*

Новые Старые