In Exchange environments with DAG and multiple database copies, the databases should normally be distributed evenly across the database servers. However, this situation can change if a failover has occurred or the databases have been activated on other servers for maintenance purposes. At some point, you may find yourself in a situation where all the databases on one server are active and the other servers are bored.
This little script provides a remedy:
#www.FrankysWeb.de #Frank Zöchling #--------------------------------- $From = "DBMover@frankysweb.de" $To = "frank@frankysweb.de" $SMTPServer = "smtp.frankysweb.de" #--------------------------------- $exsnapin = Add-PSSnapin *exchange* $Databases = Get-MailboxDatabase $DBStatus = @() [string]$mail = "<b>The mailbox server for the following databases has been changed</b> " foreach ($database in $databases) { $DBName = $database.Name $DBPreferedServer = ($database.ActivationPreference | where {$_.value -eq "1"}).key.name $DBCurrentServer = ($database.Server).name if ($DBPreferedServer -ne $DBCurrentServer) { write-host "Active mailbox server for database $DBName is changed to server $DBPreferedServer (was active on $DBCurrentServer)" -ForegroundColor yellow $MoveDB = Move-ActiveMailboxDatabase $DBName -ActivateOnServer $DBPreferedServer $DBStatus += new-object PSObject -property @{Database="$DBName";DBPreferedServer="$DBPreferedServer";DBCurrentServer="$DBCurrentServer";DatabaseMove="yes"} } else { write-host "Database $DBName is active on the designated server" -ForegroundColor green $DBStatus += new-object PSObject -property @{Database="$DBName";DBPreferedServer="$DBPreferedServer";DBCurrentServer="$DBCurrentServer";DatabaseMove="no"} } } if ($DBStatus.databasemove -contains "yes") { $DBmoved = $DBStatus | where {$_.Databasemove -match "yes"} [string]$mail += $DBmoved | ConvertTo-Html Send-MailMessage -From $from -To $to -SmtpServer $SMTPServer -Subject "Mailbox databases redistributed" -Body $mail -BodyAsHTML -Encoding UTF8 }
The script distributes all databases to the corresponding servers. The script can be executed manually or via the task scheduler. As soon as the databases have been distributed according to their preference, a notification email is sent.
Only the recipient, sender and SMTP server need to be specified in the upper part of the script. This setting can be used via the task scheduler to execute the script at a selected time: