• Home
  • About
  • Blog
  • Training
  • Books
  • Contact
  • Advertise
    • Email
    • Facebook
    • Twitter
    • RSS

Practical 365

  • Office 365
  • Exchange 2019
  • Exchange 2016
  • Exchange 2013
  • Hybrid
  • Certificates
  • PowerShell
  • Migration
You are here: Home / Exchange Server / How to Rebalance Mailbox Databases in an Exchange Server Database Availability Group

How to Rebalance Mailbox Databases in an Exchange Server Database Availability Group

October 31, 2010 by Paul Cunningham 61 Comments

After an outage or maintenance to the Exchange 2010 or Exchange 2013, or Exchange 2016 Mailbox servers in a Database Availability Group you may find that the mailbox databases are no longer balanced across all of the DAG members.

For example after applying updates to DAG members you may see that all of the mailbox databases are active on a single DAG member.

1
2
3
4
5
6
7
8
[PS] C:\>Get-MailboxDatabase | ft name, server, activationpreference -AutoSize
 
Name                Server ActivationPreference
----                ------ --------------------
Mailbox Database 02 EX1    {[EX2, 1], [EX1, 2]}
Mailbox Database 01 EX1    {[EX1, 1], [EX2, 2]}
Mailbox Database 03 EX1    {[EX1, 1], [EX2, 2]}
Mailbox Database 04 EX1    {[EX2, 1], [EX1, 2]}

You can see in the above output that all of the mailbox databases are active on server EX1, even though some of them have EX2 as a preferred server.

Exchange Server 2010 Service Pack 1 shipped with a script that allows you to automatically redistribute mailbox databases to their first activation preference. The script can be found in the Scripts folder of the Exchange Server 2010 installation path, which by default would be C:Program FilesMicrosoftExchangeV14Scripts.

You can use the script to output a report of the current mailbox database distribution among the DAG members.

1
2
3
4
5
6
7
8
[PS] C:\Program Files\Microsoft\Exchange Server\V14\Scripts\>.\RedistributeActiveDatabases.ps1 -DagName DAG -ShowDatabase
DistributionByServer | ft
 
ServerName           TotalDbs      ActiveDbs     PassiveDbs PreferenceCoun     MountedDbs  DismountedDbs DagName
                                                            tList
----------           --------      ---------     ---------- --------------     ----------  ------------- -------
EX2                         4              0              4 {2, 2}                      0              0 dag
EX1                         4              4              0 {2, 2}                      4              0 dag

To rebalance the mailbox databases based on activation preference use the following script parameters.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
[PS] C:\Program Files\Microsoft\Exchange Server\V14\Scripts\>.\RedistributeActiveDatabases.ps1 -DagName DAG -BalanceDbsBy
ActivationPreference
 
***************************************
Balance DAG DBs
Thursday, October 28, 2010 10:16:36 PM
***************************************
Dag                                :   dag
ServerCount                        :   2
DatabaseCount                      :   4
CopiesCount                        :   8
 
----------------------------
Starting Server Distribution
----------------------------
 
ServerName TotalDbs ActiveDbs PassiveDbs PreferenceCountList MountedDbs DismountedDbs DagName
---------- -------- --------- ---------- ------------------- ---------- ------------- -------
EX1               4         4          0 {2, 2}                       4             0 dag
EX2               4         0          4 {2, 2}                       0             0 dag
 
 
-----------------------
Starting Database Moves
-----------------------
 
Considering move of 'Mailbox Database 04' from 'ex1' (AP = 2) to 'EX2' (AP = 1)...
 
Confirm
Are you sure you want to perform this action?
Moving mailbox database "Mailbox Database 04" from server "ex1.exchangeserverpro.local" to server
"EX2.exchangeserverpro.local".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [?] Help (default is "Y"): a
Database 'Mailbox Database 04' successfully moved from 'ex1' to 'ex2'.
 
ServerName ActiveDbs PassiveDbs
---------- --------- ----------
EX1                3          1
EX2                1          3 `n
Considering move of 'Mailbox Database 02' from 'ex1' (AP = 2) to 'EX2' (AP = 1)...
 
Confirm
Are you sure you want to perform this action?
Moving mailbox database "Mailbox Database 02" from server "ex1.exchangeserverpro.local" to server
"EX2.exchangeserverpro.local".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [?] Help (default is "Y"): a
Database 'Mailbox Database 02' successfully moved from 'ex1' to 'ex2'.
 
ServerName ActiveDbs PassiveDbs
---------- --------- ----------
EX1                2          2
EX2                2          2 `n
 
----------------
Summary of Moves
----------------
Successfully moved      : 2
Moved to less preferred : 0
Failed to move          : 0
Not moved               : 2
 
Start time              : Thursday, October 28, 2010 10:16:35 PM
End time                : Thursday, October 28, 2010 10:17:51 PM
Duration                : 00:01:15.3764472
 
 
 
DbName                    : Mailbox Database 01
ActiveOnPreferenceAtStart : 1
ActiveServerAtStart       : ex1
ActiveOnPreferenceAtEnd   : 1
ActiveServerAtEnd         : ex1
IsOnMostPreferredCopy     : True
MoveStatus                : NoMoveAttempted
 
DbName                    : Mailbox Database 02
ActiveOnPreferenceAtStart : 2
ActiveServerAtStart       : ex1
ActiveOnPreferenceAtEnd   : 1
ActiveServerAtEnd         : ex2
IsOnMostPreferredCopy     : True
MoveStatus                : MoveSucceeded
 
DbName                    : Mailbox Database 03
ActiveOnPreferenceAtStart : 1
ActiveServerAtStart       : ex1
ActiveOnPreferenceAtEnd   : 1
ActiveServerAtEnd         : ex1
IsOnMostPreferredCopy     : True
MoveStatus                : NoMoveAttempted
 
DbName                    : Mailbox Database 04
ActiveOnPreferenceAtStart : 2
ActiveServerAtStart       : ex1
ActiveOnPreferenceAtEnd   : 1
ActiveServerAtEnd         : ex2
IsOnMostPreferredCopy     : True
MoveStatus                : MoveSucceeded

The outcome of the moves can be seen here. Each mailbox database in the DAG is now active on its preferred server.

1
2
3
4
5
6
7
8
[PS] C:\>Get-MailboxDatabase | ft name, server, activationpreference -AutoSize
 
Name                Server ActivationPreference
----                ------ --------------------
Mailbox Database 02 EX2    {[EX2, 1], [EX1, 2]}
Mailbox Database 01 EX1    {[EX1, 1], [EX2, 2]}
Mailbox Database 03 EX1    {[EX1, 1], [EX2, 2]}
Mailbox Database 04 EX2    {[EX2, 1], [EX1, 2]}

Paul Cunningham

Paul is a Microsoft MVP for Office Apps and Services and a Pluralsight author. He works as a consultant, writer, and trainer specializing in Office 365 and Exchange Server.

Exchange Server DAG, Exchange 2010, Exchange 2013, Exchange 2016, Exchange Management Shell, Scripts, SP1

Comments

  1. M G says

    November 24, 2012 at 10:22 pm

    Hi,
    Thanks Paul
    But how can i make it run automatically ?
    i mean it asks to verify moving databases but i like this script every night run as a scheduled task and fully automatic (i do not want to enter “y” press enter and …)
    i like it to be run without asking for verification

    Reply
    • Paul Cunningham says

      November 25, 2012 at 7:39 pm

      Add…

      -confirm:$false

      …to the end of the command.

      Reply
      • Ahmed Gamal says

        July 22, 2019 at 7:03 pm

        Run automatically by scheduler task on Action :

        Program/script:
        Start a program: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

        Add arguments:
        -version 4.0 -NonInteractive -WindowStyle Hidden -command “. ‘C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1′; Connect-ExchangeServer -auto; .’C:\Program Files\Microsoft\Exchange Server\V15\Scripts\RedistributeActiveDatabases.ps1’ -DagName DAG-SAPTCO -BalanceDbsByActivationPreference -confirm:$false”

        Reply
  2. Hein says

    February 15, 2013 at 7:35 am

    Weird. Can’t see what i am doing wrong. I get this:

    At C:Program FilesMicrosoftExchange ServerV14scriptsRedistributeActiveDatabases.ps1:1928 char:3
    + return $moveSuccessful
    + ~~~~~~~~~~~~~~~~~~~~~~
    Control cannot leave a finally block.
    At C:Program FilesMicrosoftExchange ServerV14scriptsRedistributeActiveDatabases.ps1:2538 char:5
    + return $success
    + ~~~~~~~~~~~~~~~
    Control cannot leave a finally block.
    + CategoryInfo : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : ControlLeavingFinally

    Hopefully you can shine a light on this and help me out 🙂

    Reply
    • Paul Cunningham says

      February 15, 2013 at 1:27 pm

      I’ve never seen that before. Has the script been modified by someone?

      Reply
    • David Garcia says

      August 15, 2013 at 5:29 am

      You need to uninstall Windows Management Framework 3.0 (KB2506146 and KB2506143). I had the same error and after the uninstall it started working. See this article:

      http://blogs.technet.com/b/exchange/archive/2012/12/14/windows-management-framework-3-0-on-exchange-2007-and-exchange-2010.aspx

      Hope this helps,

      David Garcia

      Reply
    • Daniel Wielosz says

      May 28, 2014 at 5:01 pm

      If you have Exchange 2010 on Windows Server 2012, you need to add -version 2.0 parameter:

      Below you can find definition of task sheduler action:

      powershell.exe -Version 2.0 -command “. ‘c:Program FilesMicrosoftExchange ServerV14binRemoteExchange.ps1’; Connect-ExchangeServer -auto;. ‘c:Program FilesMicrosoftExchange ServerV14ScriptsRedistributeActiveDatabases.ps1’ -DagName DAG -BalanceDbsByActivationPreference -confirm:`$true”

      Reply
  3. David says

    March 20, 2013 at 9:50 pm

    paul

    can you shed some light…..? IM getting this when i run issue this cmd

    thanks

    .RedistributeActiveDatabases.ps1 -DagName DAG -ShowDatabase
    DistributionByServer | ft

    [PS] C:Program FilesMicrosoftExchange ServerV14scripts>.RedistributeActiveDatabases.ps1 -DagName DAG -ShowDatabase
    DistributionByServer | ft
    C:Program FilesMicrosoftExchange ServerV14scriptsRedistributeActiveDatabases.ps1 : Parameter cannot be processed
    because the parameter name ‘ShowDatabase’ is ambiguous. Possible matches include: -ShowDatabaseCurrentActives -ShowData
    baseDistributionByServer -ShowDatabaseDistributionBySite.
    At line:1 char:34
    + .RedistributeActiveDatabases.ps1 <<<< -DagName DAG -ShowDatabase DistributionByServer | ft
    + CategoryInfo : InvalidArgument: (:) [RedistributeActiveDatabases.ps1], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameter,RedistributeActiveDatabases.ps1

    Reply
    • Paul Cunningham says

      April 2, 2013 at 9:29 pm

      -ShowDatabaseDistributionByServer is all on one line. There’s a carriage return that shouldn’t be there.

      Reply
  4. Gary H says

    April 3, 2013 at 2:29 am

    Thanks Paul.. It works like a charm.

    Is there a Script to Automatically Rebalance going forth? or is the only method to run this rebalance script?

    Reply
    • Paul Cunningham says

      April 3, 2013 at 9:50 am

      That is the script, yes.

      Reply
  5. Christian says

    April 27, 2013 at 5:56 am

    Hi Paul,
    Do you know a way to include an email report the result of the command RedistributeActiveDatabases.ps1 -DagName DAG -BalanceDbsBy ActivationPreference in the script?

    Reply
    • Jamille says

      June 5, 2013 at 11:38 pm

      Here’s a script to run a dag rebalance and to email you the results. You will have to change the variables below the main comments to suit your environment

      Edit: removed

      Reply
      • Paul Cunningham says

        June 6, 2013 at 11:07 am

        Jamille, I’ve removed your script from the comment. I recommend hosting your script somewhere like the TechNet Script Gallery so you can just link people to it.

        http://gallery.technet.microsoft.com/scriptcenter

        Reply
  6. Wayne says

    June 14, 2013 at 4:30 pm

    Hi Paul

    What if i have 3 servers in single DAG (All roles installed on each) 2 are active/passive and 3rd is just passive , how do i make sure that the DB’s end up back on the original place and leave the 3rd as passive?

    Reply
    • Paul Cunningham says

      June 14, 2013 at 8:17 pm

      There are no active/passive servers in a DAG. There are only active database copies and passive database copies.

      If you want to control which database copy becomes active when the rebalancing script is run as shown above, then you would set that database copy’s activation preference to 1.

      Reply
  7. Joe Hardy says

    November 15, 2013 at 3:28 am

    What kind of impact does this have on outlook clients in a 24/7/365 shop? Is there a default level of availability this script uses? ie: “none” – “best availibility”
    Wondering if end users will see any performance hits or disconnects in outlook if we run this cmdlet / script.
    Thanks,
    Joe

    Reply
    • Paul Cunningham says

      November 17, 2013 at 10:24 am

      Good question. I think it honors the setting on the database, but a quick scan through the script code didn’t find where that might be controlled.

      There’s always a risk even during a planned switchover that something will go wrong of course.

      Reply
  8. Jetty says

    December 13, 2013 at 5:40 am

    Question – I am not an exchange admin and am working my way through some Exchange items and would like to understand this better. What would happen in the event of a failure if the active database is mounted on the server with the activation preference of 2?

    Reply
    • Paul Cunningham says

      December 13, 2013 at 5:58 pm

      In a failure situation a process called Best Copy Selection evaluates a number of factors and that is how the database copy to attempt to bring online is chosen. Activation preference is one of those factors but it is not the only one.

      If you’re asking if its possible that db copy AP=1 could come online, yes that is possible, if Best Copy Selection chooses that copy.

      Reply
  9. James Slack says

    January 11, 2014 at 1:06 am

    Hi Paul,

    Is there a way to mount a DB on a specific server in a DAG when it is currently mounted on a different server in that DAG?

    We have 12 DBs and 2 servers (ignoring DR). Say I wish to mount only DB7 on DB2 instead of DB1 – how would I do this?

    The reason I ask is that we get some issues when we have to reboot one of the DAG servers. The DBs should all fail over to the other server, but sometimes one or two get stuck in limbo. This makes the other server take 19 minutes (due exchange services) to boot and those DBs that dont fail over are stuck offline until it comes back. I do the reboot correctly, stopping services etc. first.

    If I can dismount DBs one at a time and mount them on the server I desire, it will be a lot better.

    I believe the mount-database command will just mount the DB in the same place.

    Thanks

    Reply
    • James Slack says

      January 11, 2014 at 1:07 am

      Typo sorry “mount only DB7 on Server2 instead of Server1 – how would I do this?” – been one of those days

      Reply
      • Paul Cunningham says

        January 12, 2014 at 9:52 pm

        For starters, you’ll avoid all this trouble if you place the DAG member in maintenance mode before you reboot it. Example here:

        https://practical365.com/how-to-install-updates-on-exchange-server-2010-database-availability-groups

        (refer to the parts on using StartDagServerMaintenance.ps1 and StopDagServerMaintenance.ps1)

        And just to be clear why this is encouraged:
        https://practical365.com/bother-running-dag-server-maintenance-mode-scripts/

        To answer your question, yes you can make any single database copy active on a DAG member without using this rebalance script. You simply do a manual switchover:

        http://technet.microsoft.com/en-us/library/dd298068(v=exchg.141).aspx

        Reply
        • James Slack says

          January 13, 2014 at 7:24 pm

          Awesome, Thanks Paul.

          Sadly we updated to 2010 from 2003 and I had no in work training and outside of work was busy with other exams. This means most of the things that are different will remain unknown until you find something by chance (usually the hard way).

          This info is exactly what I needed, thank you.

          Time for me to get learning 2010… probably will have that down just in time to go to 2013.

          Reply
        • Paul Cunningham says

          January 14, 2014 at 1:24 pm

          A lot of what you’ll learn for 2010 is still relevant in 2013 anyway, so hit it hard and you’ll be better off in the long run. Really it was the 2003 -> 2007/2010 jump that was the biggest in terms of new stuff to learn.

          There’s some free video training here if you or your team mates need somewhere to start:
          https://practical365.com/exchange-2010-free-training-videos/

          Reply
  10. Rosario says

    March 1, 2014 at 12:09 am

    Paul, thanks, another great article. My question:

    In a DAG none of the databases is mounted on one primary server. They are mounted on the two others. So I would like to redistribute or do a manual switch over, but before doing that, I would ask WHY were they mounted on the other two servers leaving that one server only with copies an no active DB?

    So is there a means to know the reason of this switch over? No hardware failure on that server, no Error entries in the Event Viewer. Where else should I investigate?

    Thanks a lot, Rosario

    Reply
    • Paul Cunningham says

      March 1, 2014 at 3:25 pm

      Switchovers and failovers are all logged in event logs. You can drill down into the Applications and Services Logs in event viewer to investigate.

      Reply
      • Rosario says

        March 6, 2014 at 1:10 am

        Thanks, I found the Event-Viewer entries and would like to mention them here for reference.

        On the faulty server have a look at Event-Viewer->Applications and Services Logs->Microsoft->Exchange->HighAvailability and same path->MailboxDatabaseFailureItems

        Reply
  11. quaaarks says

    March 28, 2014 at 2:36 am

    Hi,
    when I use this script: .RedistributeActiveDatabases.ps1 -DagName dag1 -ShowDatabaseDistributionByServer | ft
    I get following error:

    The operation couldn’t be performed because object ‘dag1’ couldn’t be found on ‘dc.domain.com’.
    + CategoryInfo : NotSpecified: (:) [Get-DatabaseAvailabilityGroup], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : [Server=EXCH1,RequestId=eea7abfb-5a4a-4885-8740-f96617cb4dc7,TimeStamp=27.03.2014 16
    :03:43] D83A179C,Microsoft.Exchange.Management.SystemConfigurationTasks.GetDatabaseAvailabilityGroup
    + PSComputerName : exch1.domain.com

    Log-Error : [16:03:43.628 UTC] Could not find DAG matching ‘dag1’!
    At C:Program FilesMicrosoftExchange ServerV15ScriptsRedistributeActiveDatabases.ps1:2801 char:3
    + Log-Error ($RedistributeActiveDatabases_LocalizedStrings.res_0089 -f $DagName) …

    I receive these errors with Exchange 2013 as well as in Exchange 2010 Environment?
    I would appreciate any help

    Reply
    • Rosario says

      March 28, 2014 at 3:23 am

      Is the name of your DAG really dag1 ?

      Reply
  12. Edwin says

    April 1, 2014 at 4:21 pm

    What rights does the account that runs the script need? Our script account recently lost domain admin rights, and keeps failing now.

    Reply
    • quaaarks says

      April 1, 2014 at 5:07 pm

      These accounts have domain-, schema-, Enterprise-rights

      Reply
  13. Gary says

    April 30, 2014 at 10:42 pm

    How would you script moving all databases to a specific server in the DAG instead of the preferred server? For instance, maintenance will be occurring on server 1 in the DAG so in preparation you move all databases to be mounted on server 2 in the DAG.

    Reply
    • Paul Cunningham says

      April 30, 2014 at 10:45 pm

      Use the start/stop DAG maintenance scripts. Demonstrated here:

      https://practical365.com/how-to-install-updates-on-exchange-server-2010-database-availability-groups/

      Reply
  14. David says

    February 23, 2015 at 6:48 pm

    Hello, Paul.

    I would like to run a script or command line cmdlet, that could move all active mailbox databases from an specific server to the server whose activation preference is 2.

    Reply
  15. David says

    February 23, 2015 at 9:03 pm

    Ok, check this crazy huge command here:

    I have not tested yet.

    It is supposed to:

    1. Check in the SERVER1, which MailboxDatabases are mounted on it
    2. It lists all MailBoxDatabases from SERVER1 where the ActivationPreference is 2
    3. Displays info about which ones will be moved to the ActivationPreference2 Server where
    4. Ignore the ones that already are on the AP2 Server.

    Get-MailboxDatabase -Server SERVER1 | Where {$_.ServerName -eq “SERVER1”} | Sort Name | ForEach {$db=$_.Name; $xNow=$_.Server.Name ;$dbown=$_.ActivationPreference| Where {$_.Value -eq 2}; Write-Host $db “on” $xNow “Move to” $dbOwn.Key -NoNewLine; If ( $xNow -ne $dbOwn.Key){Write-host “Already On AP 2″ -ForegroundColor Red} {Write-Host ” Moving to” -ForegroundColor Blue; Move-ActiveMailboxDatabase $db – ActivateOnServer $dbOwn.key -confirm:$True} Else {Write-Host ” OK” -ForegroundColor Green}}

    Reply
    • Paul Cunningham says

      February 23, 2015 at 9:49 pm

      Ok. Good luck with your testing?

      Reply
      • David says

        February 26, 2015 at 7:05 pm

        Ok, with a few tweaks here and there, this is the final ‘WORKING!’ version:

        Move All Databases From One Server to its Activation Preference 2

        Get-MailboxDatabase -Server SERVER1| Where {$_.ServerName -eq “SERVER1”} | Sort Name | ForEach {$db=$_.Name; $xNow=$_.Server.Name ;$dbown=$_.ActivationPreference | Where {$_.Value -eq 2}; Write-Host $db “on” $xNow “Will be moved to” $dbOwn.Key -NoNewLine; If ( $xNow -ne $dbOwn.Key){Write-host ” >>> Moving…” -ForegroundColor Red; Move-ActiveMailboxDatabase $db -ActivateOnServer $dbOwn.key -confirm:$False} Else {Write-Host ” – Already on Activation Preference 2″ -ForegroundColor Green}}

        Reply
        • Paul Cunningham says

          February 27, 2015 at 1:37 pm

          Gigantic PowerShell one-liners are messy and difficult to read and understand. Why not write it as a script instead? You’ll thank yourself later.

          Reply
  16. Greg says

    September 7, 2015 at 12:50 pm

    Are there any ramifications on scheduling this script to run periodically/on startup?

    Reply
    • Paul Cunningham says

      September 7, 2015 at 12:56 pm

      I wouldn’t run it on startup, that’s not the right time to be doing a DAG rebalance.

      Some people choose to schedule it to run just prior to their backups, if the backups depend on certain database copies being active. Others might run it nightly or weekly depending on how neat and tidy they like things to be.

      Personally I would just run it manually after completing any maintenance.

      Reply
  17. Robban says

    October 15, 2015 at 7:15 pm

    Hi

    I upgraded to CU10 and this wonderful script stopped working. On my still CU7 it works.
    Anyone noticed this?

    Errro:
    “Cannot process argument transformation on parameter ‘Identity’. Cannot convert value “DATABASENAME” to type “Microsoft.Exchan
    ge.Configuration.Tasks.DatabaseCopyIdParameter”. Error: “Cannot convert hashtable to an object of the following type: M
    icrosoft.Exchange.Configuration.Tasks.DatabaseCopyIdParameter. Hashtable-to-Object conversion is not supported in restr
    icted language mode or a Data section.”
    WARNING: [08:51:27.449 UTC] Cannot bind argument to parameter ‘mdb’ because it is null.Cannot process argument
    transformation on parameter ‘Identity’. Cannot convert value DATABASENAME” to type

    Regards Robban

    Reply
  18. Gareth Hillary says

    December 14, 2015 at 9:13 pm

    This article looks like exactly what we need but when I try to go and run it I fall at the first hurdle.

    We are using Exchange 2013 so the scripts are in a slightly different folder to the syntax however I have edited it to reflect the appropriate folder, V15 instead of 14.

    I get the following output, please can you tell me where I am going wrong:

    [PS] C:\>C:Program FilesMicrosoftExchange ServerV15Scripts>.RedistributeActiveDatabases.ps1 -DagName DAG -ShowData
    base DistributionByServer | ft
    C:Program : The term ‘C:Program’ is not recognized as the name of a cmdlet, function, script file, or operable
    program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:1
    + C:Program FilesMicrosoftExchange ServerV15Scripts>.RedistributeActiveDatab …
    + ~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (C:Program:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    Reply
    • Gareth Hillary says

      December 14, 2015 at 9:29 pm

      I am a pillock – I have realised how to execute the script. Navigate to the folder first via changing directory from the command line.

      Doh!

      Reply
  19. sanju says

    February 19, 2016 at 12:54 pm

    For me it never works

    S] D:Exchange Serverv15Scripts>.RedistributeActiveDatabases.ps1 -DagName DAG01 -BalanceDbsByActivationPreference

    annot convert value “DAG01″ to type
    Microsoft.Exchange.Data.Directory.SystemConfiguration.DatabaseAvailabilityGroup”. Error: “Cannot convert the
    DAG01” value of type “Deserialized.Microsoft.Exchange.Data.Directory.SystemConfiguration.DatabaseAvailabilityGroup”
    o type “Microsoft.Exchange.Data.Directory.SystemConfiguration.DatabaseAvailabilityGroup”.”
    t D:Exchange Serverv15ScriptsRedistributeActiveDatabases.ps1:2801 char:3
    $script:dag = Get-DatabaseAvailabilityGroup $DagName -Status
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : MetadataError: (:) [], ArgumentTransformationMetadataException
    + FullyQualifiedErrorId : RuntimeException

    Log-Error : [02:40:33.145 UTC] Could not find DAG matching ‘DAG01’!
    t D:Exchange Serverv15ScriptsRedistributeActiveDatabases.ps1:2806 char:3
    Log-Error ($RedistributeActiveDatabases_LocalizedStrings.res_0089 -f $DagName) …
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Log-Error

    When i run the Get-DatabaseAvailabilityGroup I see Correct DAG Names. I have removed the Server names here for example

    [PS] D:Exchange Serverv15Scripts>Get-DatabaseAvailabilityGroup

    Name Member Servers Operational Servers
    —- ————– ——————-
    DAG01
    DAG02
    DAG03
    DAG04

    I am 100 percent Sure DAG name is correct. I am on exchange 2013 CU8

    Reply
    • Paul Cunningham says

      February 19, 2016 at 4:47 pm

      Are you doing this in the Exchange Management Shell?

      Reply
      • Will says

        August 20, 2016 at 7:04 am

        I had the same issue when I was using Powershell ISE with Exchange snap-in. Run this in EMS and it worked. Thanks Paul.

        Reply
  20. Stefan says

    March 9, 2016 at 3:57 am

    It seems that this script no longer works after CU11 which I think has to do with RPS proxying. Is there a workaround for CU11 to use this script? From what I have read, CU12 will restore RPS original functionality so this may be moot.

    Reply
    • Paul Cunningham says

      March 9, 2016 at 11:38 am

      Wouldn’t surprise me to hear that CU11 broke it. I don’t know if any fix, and CU12 is probably going to be released this month since the last update was in December.

      Reply
  21. Adams Toomer says

    April 15, 2016 at 12:30 am

    What you actually WANT to activate them by their second preference, for maintenance on storage, is there a command to do so?

    Reply
  22. Adams Toomer says

    April 15, 2016 at 12:31 am

    *What if you actually WANT to activate them by their second preference, for maintenance on storage, is there a command to do so?

    Reply
  23. Mike says

    April 28, 2016 at 3:46 pm

    Hi, Is it safe to copy database.edb and the logs from passive database member without dismounting the database? I wanted to manually copy the db from HQ to DR site and synchronize it as a dag member.

    Thank you.

    Reply
    • Mike Walker says

      September 9, 2016 at 7:24 am

      Negative! Never do anything directly with database/log files while the database is still mounted. There are many sites documenting how to do manual seeds by copying/restoring the database, but all require at least a brief outage to dismount and make the database consistent.

      Another way is to create new databases with the DAG config you want and then move all existing mailboxes to them, so the DAG synch happens at the same time as the moves.

      Reply
  24. Felice Gioino says

    August 2, 2016 at 10:39 pm

    Is it possible to balance DB’s by DAG?

    Reply
  25. egemen says

    April 25, 2017 at 8:03 pm

    Hello Paul,

    I run the script without any issue but even after the databases move to primary one, they instantly return their first state what could cause this issue?

    Regards,

    Reply
    • Paul Cunningham says

      April 25, 2017 at 8:44 pm

      You’ll need to look at your event log to see what is being logged when the active database copies are moving.

      Reply
  26. Great H says

    May 23, 2017 at 1:15 pm

    Thanks Paul sincerely, every issues can be resolved after reading your articles instead of open case to Microsoft and waste a lot of time, truely expert.

    Reply
  27. Tony says

    September 29, 2018 at 3:40 pm

    Hi Paul. Sorry for the comment on such an old article, but when i try running it i get this

    Sending data to a remote command failed with the following error message: The WinRM client sent a request to the remote
    WS-Management service and got a response saying the request was too large. For more information, see the about_Remote_
    Troubleshooting Help topic.

    I did some gooling, and made a change to the Web.config file for the powershell virtual directory. That makes the script work. https://www.pei.com/2015/10/windows-server-management-request-too-large/
    But then when i open Powershell for exchange again, it spits out all kinds of errors that it cant connect to the other servers because too many requests, etc..
    Unless i have to make this change on all servers. I just wanted to verify that this wont break anything else as far as you know.

    Reply

Leave a Reply Cancel reply

You have to agree to the comment policy.

Recent Articles

  • How to Avoid ‘Scope Creep’ in Email Migration Projects
  • The Azure Ink Recognizer: How it works and integrates into SharePoint – Part 1
  • Using Powershell to apply Messaging Policies to Teams Users
  • Deciding whether to enable Priority Notifications in Microsoft Teams
  • Skype for Business Online is being retired – how should you prepare?
Practical 365

Training Courses

  • Configuring and Managing Office 365 Security
  • Office 365 Admin Playbook
  • Exchange 2016 Exam 70-345
  • Managing Exchange Mailboxes and Distribution Groups in PowerShell
  • More Training Courses...

Recommended Resources

  • Office 365 Security Resources
  • Office 365 Books
  • Exchange Server Books
  • Exchange Server Migrations
  • Exchange Analyzer
  • Digicert SSL Certificates

About This Site

Practical 365 is a leading site for Office 365 and Exchange Server news, tips and tutorials. Read more...
  • Email
  • Facebook
  • Twitter
  • RSS

Copyright © 2019 Quadrotech Solutions AG · Disclosure · Privacy Policy
Alpenstrasse 15, 6304 Zug, Switzerland

We are an Authorized DigiCert™ SSL Partner.