Sunday, December 29, 2024

Rebalance Mailbox Databases in an Exchange Server DAG via TaskManager

Abstract: This short howto explain how to rebalance Mailbox Databases in an Exchange Server Database Availability Group via the task manager.

During maintenance (e.g. Installation Windows updates) it might happen that the DBs arenĀ“t correctly rebalanced. If you wish to automate the task via taskmanager, then follow the steps below.

Preparation:

a.) Before you perform the task you need to create a task user which will be used to run the exchange powershell RedistributeActiveDatabases.ps1. Therefore create a account with the proper rights.

b.) Create a folder “C:\ScheduledScripts” and create a new file (BalanceMailboxDBsInsideDAG.ps1) with the following content inside that folder:

if (((Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.SnapIn -ErrorAction SilentlyContinue)) -eq $null )
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
}

$Date = (Get-Date -format "yyyy-MM-dd_HH-mm")

cd "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\"
.\RedistributeActiveDatabases.ps1 ā€“DagName EXCHDAG01 ā€“BalanceDbsByActivationPreference ā€“confirm:$false > C:\ScheduledScripts\log\$Date.txt

Exit

Adjust the DAG name if needed!

c.) Create a “log” folder inside C:\ScheduledScripts (C:\ScheduledScripts\logs).

This howto is based on Exchange 2016 (running on Windows 2012 R2), but should work also on Exchange 2010 or Exchange 2013.

This todo might conflict with your company security policy, so check that before you implement it!

1.) Start the task scheduler and create a new basic task

2.) Inside the general tab enter:

2a.) Give the task a proper name inside the name field (e.g. “Balance Mailbox databases in a DAG”)

2b.) click on “Change User or Group” and select the taskuser you created

2c.) Select “Run wheter user is logged on or not”

2d.) Select “Run with highest privileges”

3.) Inside the triggers tab perform the following:

3a.) Change the settings to daily and then to 5:00 oĀ“clock (or some other timeframe which fits your needs).

3b.) Select the “Stop task if it runs longer than” and choose “2 hours” (or some other timeframe which fits your needs).

4.) Inside the actions tab perform:

4a.) press on new to create a new task

4b.) Inside the “program/script” enter the following:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

4c.) Inside the “Add arguments” enter the following:

-nologo -NonInteractive -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; C:\ScheduledScripts\BalanceMailboxDBsInsideDAG.ps1"

4d.) Inside the “Start in” enter the following:

C:\ScheduledScripts

4e.) click on ok to close and add the action

5.) Inside the conditions tab perform the following:

5a.) remove the check mark for the power options.

6.) Inside the settings tab perform the following:

6a.) Change the “stop the task if it runs longer than” to a appropriate time (e.g. 1-2 hours)

To troubleshoot the task scheduler last runtime check out the following howto.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Stay Connected

35FollowersFollow
- Advertisement -

Latest Articles