How many times each day do you get asked, “Is there a problem with the Exchange server?”
If you’re like me then you get asked this question at least once per day. Of course there usually isn’t anything wrong with our Exchange servers
but once the question has been asked then you have no choice but to investigate and confirm that everything is okay.
In this article I’m going to demonstrate how you can quickly check the health of your Exchange Server 2010 mailbox servers, and share a script with you that can help to speed up this task.
Note: a better version of this script is now available here.
Exchange Server 2010 has a series of PowerShell cmdlets that make it easy to do a health check of mailbox servers. For example, we can:
- Run Test-Servicehealth to check the required services are all running
- Run Get-MailboxDatabase to check whether the mailbox databases are mounted
- Run Test-MapiConnectivity to verify that the databases are responding to MAPI requests
- Run Test-MailFlow to confirm that email is able to pass successfully between two servers
- Run Get-MailboxDatabaseCopyStatus for DAG members to check the database copy status, queues, and content indexes
That’s quite a few cmdlets to run, especially if we’ve got more than one mailbox server in the organization. And of course each of those cmdlets needs to run and show you output that you need to interpret.
I like to make life a bit easier and use PowerShell scripts to speed up these types of tasks. So naturally I put together a script for performing all of the above tests (and a few more) on my mailbox servers and display a nice simple colour-coded output so that I can tell at a glance whether there might be a problem.
This isn’t designed to do a diagnosis of any problems, it just checks the fundamentals and gives me a simple pass/fail and a few other indicators that I can then troubleshoot further if necessary.
Download the script file here: Test-MailboxServer.ps1 (downloaded 4939 times so far)
Note: a better version of this script is now available here.
Extract Test-MailboxServer.ps1 from the Zip file and run it in your Exchange Management Shell to see output such as this:

If you have any questions or bugs to report please let me know in the comments below.
Change log:
- V1.0, 20/11/2011 – Initial version
- V1.1, 10/01/2011 – Fixed $null’s, bugs with Recovery DBs, and ping failure scenarios




Hi! I get the following error: The file xxxxxxx is not digitally signed. The script will not execute on the system.
Yep, the script isn’t signed. You can change your execution policy to get around that, see here:
http://technet.microsoft.com/en-us/library/ee176961.aspx
Thanks. Changed it to unrestricted, ran the script, then changed back to remotesigned.
Hi Paul,
Great script. Thanks for sharing. It works great on all the mailbox servers in my DAG except for a server that I have that only holds passive database copies. On that server the mail flow test fails with an unable to open message store. Not a big deal, I was just wondering if you knew why.
Thanks again.
Kevin
Makes sense if there are no active databases on that DAG member then it can’t perform that test. I’ll update the script to skip that test when there are no active DBs.
Hi Paul,
I just remembered that there is one active database on that server. There are no copies of the database anywhere. This is the error message I get for that server.
Kevin
ERROR MSG:
Mail flow test: [Microsoft.Mapi.MapiExceptionRecoveryMDBMismatch]: MapiExceptionRecoveryMDBMismatch: Unable to open message store. (hr=0×80004005, ec=1165)
+ CategoryInfo : InvalidData: (:) [Test-Mailflow], RecipientTaskException
+ FullyQualifiedErrorId : DB35BF00,Microsoft.Exchange.Monitoring.TestMailFlow
Is there a recovery database on that server as well?
What happens if you just run Test-MailFlow for that server?
Hi Paul,
Cool script, I’ll definitely be keeping it on hand.
Just one quick note on using $nul as opposed to $null: $nul is settable like any other variable, $null is and always will be null.
If someone has, for whatever reason, set $nul to a value, this could play havoc with some scripts.
Cheers,
Chris
Good catch, I’ll fix that up in the next update.
Fixed in V1.1
Hi Paul,
Test-Mailflow on this server gives me the error: Unable to open message store.
This server does have a recovery database on it. Is that the cause of the error?
Thanks,
Kevin
Yep that looks like the cause, I just need to update the script to deal with that scenario.
Hi Kevin, I’ve put some RDBs in my test lab and can’t seem to reproduce the error you’re getting. Could you please try downloading the new version of the script and trying again?
Also, when you’re running the script are you running it on the server that only has an RDB on it, or do you see the error when you run the script on another server or on your own workstation?
Hi Paul,
I’ll download the latest build and try it later.
Thanks,
Kevin
Thanks Paul.
Thanks
Nice script
Hi Paul,
its working fine..I want to send this report as an email. Please let me know to proceed??
Hi Jagan, I’ll see about adding that as an enhancement in the next version, but if you don’t want to wait you can go ahead and learn about sending email reports from scripts using my tutorial series starting here:
http://exchangeserverpro.com/powershell-how-to-send-email
Hello Paul, Thanks !!! I will try to write the script to send an email….
HI Paul
Am running this script under my lab 2010 which is having 2 Mailbox Server and NO DAG is implemneted till..
When i ran the script it from the C: drive in server name SRV1
it showing as
Checking SRV1
Ping test:—–Checking SRV2
Ping Test: [PS] C:\>
What is the issue
Are you running it in the Exchange Management Shell or just a Powershell session?
Hi Paul
Am running this From Exchange Mgmt Shell.
Hi Ram, sorry for the delay. I get that same problem if I try to run the script for a server that doesn’t exist. I guess that means the ping fails and the script is not handling that properly.
So it could be that in your case the ping is failing too, perhaps due to a firewall? Can you ping the servers normally from the computer that you’re running the script on?
Ram, I’ve updated the script to V1.1 with better handling of failed ping scenarios. Please try the new version and let me know how you go.
Hi Paul,
Good day to you! Just wondering if you have the new version to send the script thru email?
Hi Dax, not yet. I’ve just returned from holidays this week though, and I’ve got a lot of improvements planned for the script including email functionality, so stay tuned
Hi Paul,
Works great, Thanks for sharing
Great Script – ran perfectly. I think I’ll tweak it and add the email functionality.
Once again another great article.
Hi Paul,
Great script, but I found one small bug.
On line 254:
$IsDAG = Get-MailboxServer $server.name
generates an error when a single server name is supplied as an argument on the command line, because it’s just a string instead of an exchange server object. When no argument is supplied, you do a Get-ExchangeServer to retrieve all of the servers, but when an argument is supplied, you’re not doing anything with it.
Change line 56 from:
$mbservers = @($server)
to this:
$mbservers = @(Get-Exchangeserver $server)
and that will fix it right up.
Thanks again,
Mike
Thanks Mike.
Thanks for this great script, very useful indeed!
Could you add:
1. Test-OutlookConnectivity (Protocol:TCP and HTTP)
2. Test-SmtpConnectivity
3 .Test-replicationhealth
4. Queue reporting (Get-TransportServer | Get-Queue)
it will be the best choice for any Exchange admin since it is a perfect combination of functionality and beauty.
Thanks again for your great work !
Sure thing, I’m working on a script to health check all the server roles in the org.
First of all, thanks for the script. is great.
when I try to export the script output to a file, it is empty. Do You know the reason?
I use this command:
C: \ Scripts>. \ Test-MailboxServer.ps1 | ConvertTo-Html | Set-Content C: \ Scripts \ Logs \ Test-MailboxServer.html
Sorry if my question is a bit silly
Thanks for everything
Not silly, the script is a bit lazy and just uses Write-Host to output to console. It wasn’t originally written with nicely formatted reports in mind
I’ll be updating it with proper PS objects and such so that HTML output is a possiblity, among other planned improvements.
Thanks for your time.
I’m testing with the command Start-Transcript-path C: \ Scripts \ Logs \ Test-MailboxServer.csv at the beginning of the script and Stop-Transcript to end.
It seems to work fine. Now I just send it by email.
Thanks for everything.
I don’t want to sound like a goober but when I try to run the script I get the following error:
The term ‘Test-MailboxServer.ps1′ is not recognized as the name of a cmdlet, function, script file……….
What am I doing wrong?
I figured it out. I had to include .\ in front of the command. Why?
Hi Tom, thats just how PowerShell scripts are executed, by using…
.\script-name.ps1
There’s some more info here:
http://technet.microsoft.com/en-us/library/ee176949.aspx
Why they designed it that way I don’t know, its just how it is
Thanks for the script. Looking forward for your next version. Sending an email alert to admin in the event of “RED” result would be nice.
Tks Paul, its a great job…
One question do you have any script to check the performance of Exchange Server 2010 on and typically installation method.
Best regards,
For performance checks I use ExPerfwiz:
http://archive.msdn.microsoft.com/ExPerfwiz
And then use this article to guide me through the analysis of the data.
http://technet.microsoft.com/en-us/library/bb201720(v=exchg.80).aspx
Tks Paul…
Hello,
Great script. Thanks a lot.
Max.
Hi Paul,
great job. Big thx for the script. When can we expect a test script for the other exchange roles
Great Scipt man! We use it all the time. Really appreciate the Go-Giver mentality!
Sunny Lowe
in polish enviroment i’ve got ‘powodzenie’ (means success) in red color – Mail flow test: Powodzenie
Hi Paul,
This is wonderful script. It made my monitoring much easier. Please keep up with your good scripting work.
Thanks Once again.
Hi Paul,
How to run the script for individual mailbox server , i mean where to modify the script.
I like the script, BUT it does not properly reflect DAG health. As noted below, your script shows everything Passed, but when we ran Test-ReplicationHealth the QuorumGroup check failed with an error on the DAG. Something to include in a future revision is Replication Health.
—— Checking MBXP01
DNS Check: Pass
Server up: Pass
Uptime (hrs): 2
Server version: Exchange 2010
Roles: Mailbox
Mailbox Server Role Services: Pass
Public Folder databases mounted: Pass
Mailbox databases mounted: Pass
MAPI connectivity: Pass
Mail flow test: Success
Thanks for a great script.