Exchange Server Database Latency MAPI Connectivity Report in Daily Email Notification
Summary
Troubleshooting Microsoft Exchange Server Latency or Connection Issues is one of important issue Exchange administrator face in routing life, after deployment of Exchange Server. In this article, we will walk through to schedule a script which can tell Exchange administrator MAPI Test connectivity and Database Latency statistics on his/her email on daily basis. This will help admin to keep an eye on database latency related stats.
Steps
We need to create two files and keep them somewhere in your Exchange drives my docs, download or C:\ drive etc where you have full permission to run these file in-case if you have used delegated account for Exchange installation. File names with extension are as below:-
- ExchangeTestMAPIConnectivityLatency.bat
- ExchangeTestMAPIConnectivityLatency.PS1
Creating .bat File
Open the ExchangeTestMAPIConnectivityLatency.bat file and paste the following path which can vary to your environment, or as per your Exchange application installation. Most of the people install Exchange Server in default OS drive C:\
PSConsoleFile "D:\Program Files\Microsoft\Exchange Server\V15\Bin\ExShell.psc1" -Command ". 'C:\Program Files\Update Services\Exchange Bats\Exchange Bats\ExchangeTestMAPIConnectivityLatency.PS1'"
You can point to this PowerShell.exe where your Exchange is installed. In this case, its installed in D:\ so its using that path, the second part of the command is the path of your .PS1 script where you place it.
Creating a .PS1 Script
We will open the ExchangeTestMAPIConnectivityLatency.PS1 script in any editor and fill the following information.
$messageParameters = @{
Subject = "Test-MAPI Connectivity-DBLatency Report - $((Get-Date).ToShortDateString())"
Body = Get-MailboxServer |
Where-Object {(get-mailboxdatabase -Server $_ ).count -gt '0'} |
ForEach-Object { Test-MAPIConnectivity -Server $_ |
Select-Object Server, Database, Result, @{Name="Latency(MS)";expression={(([TimeSpan] $_.Latency).TotalMilliSeconds)}}, Error} |
Sort-Object Server, Database |
ConvertTo-Html |
Out-String
From = "Exchange-DB-Latency@mstechguru.ae"
To = "administrators@mstechguru.ae"
SmtpServer = "smtp.mstechguru.ae"
}
In Script you can change Subject value, From Value, To Value and SmtpServer value as per your environment. In From value, we can put any dummy email ID which will later appear in Email from the option. So no need to put any valid email address in From. In To option we have to put some valid email address for Exchange Administrator or the Exchange admins teams who are responsible for Exchange Servers in organization, so They will receive email notification on daily basis and be well aware of Exchange Server's Databases Latency Status.
Note:- In SMTP setting you can put your CAS Server FQDN if you are running Exchange 2013, and for Exchange Server 2016 you can put FQDN of your any Mail-box Server. At this point, we have created both files and keep them in C:\ drive somewhere. Now we will create a Schedule Task to run this .bat file on a daily basis at a particular time like when an administrator takes coffee or tea at morning he/she can schedule this at that time to have a view to his inbox for Exchange Databases Heath & status.
Scheduling a Task in Exchange
How you schedule your task for this .bat file to run, you can follow the link below:-
Results in Email
When task will trigger you will receive an email having Exchange Servers all Databases Latency stats and MAPI Testing status.
This will help you to keep an eye on Exchange DB Latency & MAPI Test Connectivity status in the mail.