Netflex Blog

powershell

Exchange Database Activation Preference

An Exchange database availability group (DAG) provides fault tolerance for your mail databases. When a mailbox server fails or when doing maintenance your users will still be able to send mail.  Unfortunately you don’t always know when a failover took place. This could be because no monitoring is in place. The moment you realize some databases failed over is properly when users are complaining of a slow mail system.

Echange-Database-Activation-Preference

 

The script checks the activation preference of the database in relation to the database status. If a database with an activation preference of one has a status else than “Mounted” it probably failed over (or has other issues). In this case the script will mail an alert to the configured recipients with a report of the databases not mounted on the preferred server.


# Check-PrefDbServer.ps1

# Checks if database is running on the preferred mailbox server, if not an email will be send.

# Created: 20-11-2014

# Created by: Michiel Elderson (Netflex)

# version: 1.0

 

$Body = @() | Out-string

$Databases = Get-MailboxDatabase

 

Foreach ($Database in $Databases){

$ActPref = $Database.ActivationPreference

$Server = $Database.Server

if (!($Actpref -like "*$Server, 1*")){

Write-host "Database $Database is NOT mounted on the preferred server" -BackgroundColor Red

$Body +="<p>Database $Database is NOT mounted on the preferred server</p>"

}

}

 

#Set email settings

$SmtpSettings = @{

To = "user1@domain.com", "user2@domain.com", "user3@domain.com"

From = "ExchangeAlert@domain.com"

Subject = "Database(s) not running on preferred server, possibly a failover occurred"

Body = $Body

SmtpServer = "SmtpServer.domain.com"

}

#Send the actual mail

Send-MailMessage @SmtpSettings –BodyAsHtml

Usage

Save the script to Check-PrefDbServer.ps1 and change the SMTP settings. You could schedule the script to run every hour.

 

Scroll to Top