• Home
  • Topics
    • Office 365
    • Teams
    • SharePoint Online
    • Exchange 2019
    • Exchange 2016
    • Exchange 2013
    • Hybrid
    • Certificates
    • PowerShell
    • Migration
    • Security
    • Azure
  • Blog
  • Podcast
  • Webinars
  • Books
  • About
  • Videos
    • Interview Videos
    • How To Guide Videos
  • Subscribe
    • Facebook
    • Twitter
    • RSS
    • YouTube

Practical 365

You are here: Home / Exchange Server / Using Test-ServiceHealth for Exchange Server Health Checks

Using Test-ServiceHealth for Exchange Server Health Checks

October 18, 2011 by Paul Cunningham 34 Comments

Exchange Server 2010 (and 2007 for that matter) ships with a useful PowerShell cmdlet called Test-ServiceHealth.

As the name suggests, Test-ServiceHealth checks the state of the services that should be running on the Exchange server. One of the best things about this cmdlet is that it checks the services depending on the Exchange server roles that are installed.

So for example, for a Hub Transport server only those services relating to the Hub Transport role will be checked. While for a “typical” Exchange 2010 server the services for the Hub Transport, Client Access, and Mailbox server roles will be checked.

Here is an example of the Test-ServiceHealth results.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[PS] C:\>Test-ServiceHealth br-ex2010-mb
 
Role                    : Mailbox Server Role
RequiredServicesRunning : True
ServicesRunning         : {IISAdmin, MSExchangeADTopology, MSExchangeIS, MSExchangeMailboxAssistants, MSExchangeMailSub
                          mission, MSExchangeRepl, MSExchangeRPC, MSExchangeSA, MSExchangeSearch, MSExchangeServiceHost
                          , MSExchangeThrottling, MSExchangeTransportLogSearch, W3Svc, WinRM}
ServicesNotRunning      : {}
 
Role                    : Client Access Server Role
RequiredServicesRunning : True
ServicesRunning         : {IISAdmin, MSExchangeAB, MSExchangeADTopology, MSExchangeFBA, MSExchangeFDS, MSExchangeMailbo
                          xReplication, MSExchangeProtectedServiceHost, MSExchangeRPC, MSExchangeServiceHost, W3Svc, Wi
                          nRM}
ServicesNotRunning      : {}
 
Role                    : Hub Transport Server Role
RequiredServicesRunning : True
ServicesRunning         : {IISAdmin, MSExchangeADTopology, MSExchangeEdgeSync, MSExchangeServiceHost, MSExchangeTranspo
                          rt, MSExchangeTransportLogSearch, W3Svc, WinRM}
ServicesNotRunning      : {}


As you can see that is a lot of useful information. But whenever possible I like to see just the minimum relevant information for my servers. In the case of Test-ServiceHealth the RequiredServicesRunning result is the thing I am most interested in.

So in this case I could run the following command to see just that information:

1
2
3
4
5
6
7
[PS] C:\>Test-ServiceHealth br-ex2010-mb | ft Role,RequiredServicesRunning -auto
 
Role                      RequiredServicesRunning
----                      -----------------------
Mailbox Server Role                          True
Client Access Server Role                    True
Hub Transport Server Role                    True


Much better.

Now suppose I wanted to run that for all of my Exchange servers. I could do that with the following command:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[PS] C:\>Get-ExchangeServer | Test-ServiceHealth | ft Role,RequiredServicesRunning -auto
 
Role                      RequiredServicesRunning
----                      -----------------------
Client Access Server Role                    True
Hub Transport Server Role                    True
Client Access Server Role                    True
Hub Transport Server Role                    True
Mailbox Server Role                         False
Mailbox Server Role                          True
Client Access Server Role                    True
Hub Transport Server Role                    True
Mailbox Server Role                          True
Client Access Server Role                    True
Hub Transport Server Role                    True


Interesting, especially the one that failed the test for the Mailbox server role. But in that output I can’t tell which server failed.

Let’s try this instead:

1
2
3
4
5
6
[PS] C:\>$servers = Get-ExchangeServer
[PS] C:\>foreach ($server in $servers) {
>> Write-Host "Checking" $server.name
>> Test-ServiceHealth $server | ft Role,RequiredServicesRunning -auto
>> }
>>


Now we get output that is a little more useful, and tells me which server failed the test.

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
Checking HO-EX2010-CAHT1
 
Role                      RequiredServicesRunning
----                      -----------------------
Client Access Server Role                    True
Hub Transport Server Role                    True
 
Checking HO-EX2010-CAHT2
 
Role                      RequiredServicesRunning
----                      -----------------------
Client Access Server Role                    True
Hub Transport Server Role                    True
 
Checking HO-EX2010-MB1
 
Role                RequiredServicesRunning
----                -----------------------
Mailbox Server Role                   False
 
Checking HO-EX2010-MB2
 
Role                RequiredServicesRunning
----                -----------------------
Mailbox Server Role                    True
 
Checking BR-EX2010-CAHT
 
Role                      RequiredServicesRunning
----                      -----------------------
Client Access Server Role                    True
Hub Transport Server Role                    True
 
Checking BR-EX2010-MB
 
Role                      RequiredServicesRunning
----                      -----------------------
Mailbox Server Role                          True
Client Access Server Role                    True
Hub Transport Server Role                    True


But it still isn’t quite enough, so let’s wrap this up into a handy script that will do the following:

  • Run Test-SystemHealth for all of the Exchange servers in the organization
  • Tell me which servers passed the test
  • Tell me which servers failed the test, and why

Here is the script code that will perform those steps.

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
#Get the list of Exchange servers in the organization
$servers = Get-ExchangeServer
 
#Loop through each server
ForEach ($server in $servers)
{
Write-Host -ForegroundColor White "---------- Testing" $server
 
#Initialize an array object for the Test-ServiceHealth results
[array]$servicehealth = @()
 
#Run Test-ServiceHealth
$servicehealth = Test-ServiceHealth $server
 
#Output the results
ForEach($serverrole in $servicehealth)
{
If ($serverrole.RequiredServicesRunning -eq $true)
{
Write-Host $serverrole.Role -NoNewline; Write-Host -ForegroundColor Green "Pass"
}
Else
{
Write-Host $serverrole.Role -nonewline; Write-Host -ForegroundColor Red "Fail"
[array]$notrunning = @()
$notrunning = $serverrole.ServicesNotRunning
ForEach ($svc in $notrunning)
{
$alertservices += $svc
}
Write-Host $serverrole.Role "Services not running:"
ForEach ($al in $alertservices)
{
Write-Host -ForegroundColor Red `t$al
}
}
}
}


The output from running the script will look something like this.

Using Test-ServiceHealth for Exchange Server Health Checks

You can now see at a glance which servers have passed the test, which ones failed, and which services aren’t running for the servers that failed.

Exchange Server Diagnostics, Exchange 2007, Exchange 2010, Exchange Management Shell, PowerShell, Test-ServiceHealth

Comments

  1. Dann says

    November 4, 2019 at 11:49 pm

    Thank you Paul. very useful

    Reply
  2. Syed says

    June 2, 2018 at 5:01 am

    Thank you PAUL!!! I LOVE YOU!! Needed to see which exact service was not running, so glad for this.

    Reply
  3. Wayne says

    March 30, 2018 at 5:54 am

    The .\Test-ExchangeServerHealth.ps1 script works quite well, but we do not have MSExchangeEdgeSync service running. This causes “Hub Transport Server Role” test failed. Is there a way to get around it?

    Thanks

    Reply
    • Paul Cunningham says

      March 30, 2018 at 10:49 am

      Test-ServiceHealth is expect it to be running. In the past I’ve simply enabled and started the service.

      Reply
  4. David says

    October 22, 2016 at 6:09 am

    Thanks for sharing this. I have a question, how do you check if all the CAS servers are accepting outlook client connections? We have in the past where all the services are running fine and server health is okay but the CAS server just doesn’t accept the Outlook connections.

    Thank you.
    David

    Reply
    • Paul Cunningham says

      October 24, 2016 at 5:40 pm

      This should help:
      https://www.practical365.com/testing-exchange-server-2013-client-access-server-health-with-powershell/

      Reply
  5. Gordon says

    February 20, 2016 at 3:53 am

    Hello,
    I would like to achieve the following and need some guidance. I would like to run a scheduled task to run the test-servicehealth but only email out to a DL when a required service is in a failed state.
    Could you help to add the necessary code to achieve this?

    Thanking you in advance.

    Gordon

    Reply
    • Paul Cunningham says

      February 20, 2016 at 10:02 pm

      Use this script, which has an -AlertsOnly switch so it will only email a report when there are errors or warnings.

      https://gallery.technet.microsoft.com/office/Generate-Health-Report-for-19f5fe5f

      Reply
  6. Krish says

    January 12, 2016 at 2:37 am

    HI Paul,

    Thanks for Providing this Wonderful Script. But can you please help me with starting the failed services, after the script shows failed services in red?

    Appreciate your help

    Thanks
    Krish

    Reply
    • Paul Cunningham says

      January 13, 2016 at 8:56 am

      There’s a Start-Service cmdlet in PowerShell, or you can use the Services.msc console.

      Reply
      • Krish says

        January 15, 2016 at 3:14 am

        Yes. But i was asking you, where i can place Start-Service cmdlet in your script.

        So that if the loop checks and shows as “services not running” then it will start the required service automatically.

        It would be a great help , if you can help me with this.

        Thanks

        Reply
        • Paul Cunningham says

          January 15, 2016 at 9:03 am

          You could add it to the section of the script that is running Test-ServiceHealth and processing the results. But I don’t really recommend that. The script can’t tell the difference between a service that is stopped due to an error, and one that is stopped on purpose due to maintenance. I recommend you let the report flag problems to you for manual attention. If you have lots of service failures you need to address the root cause of those.

          Reply
          • krish says

            January 15, 2016 at 4:06 pm

            Got you Paul. Thanks a lot.

            Best Regards,
            Krish

  7. O.R says

    July 31, 2015 at 6:08 pm

    Hi Paul,
    this is a great script. Is there any fix for the EdgeSync failure in report available ?
    Thanks a lot

    Reply
    • Paul Cunningham says

      July 31, 2015 at 8:14 pm

      Start the service?

      Reply
  8. art says

    April 15, 2014 at 6:12 pm

    Hi Paul;
    Thanks for the great script works perfect.
    if you may need to ask my reports has generate only “Hub Transport Server Role Services status is Fail”
    is there something to do? or just ignore?
    thnx

    Reply
    • Paul Cunningham says

      April 17, 2014 at 8:41 pm

      Run Test-ServiceHealth on a Hub Transport that is reporting a fail and see what it says.

      My guess is EdgeSync isn’t running, which is harmless if you don’t have Edge servers, but will show as a fail in the report because the test cmdlet considers it a required service.

      Reply
  9. Paul says

    May 2, 2013 at 8:39 pm

    Hi,
    If there I get
    Role : Client Access Server Role
    RequiredServicesRunning : False

    How to make it to true?

    Reply
    • Paul says

      May 3, 2013 at 10:54 am

      Run the command on its own for that server (look at the first example in the article) and it will tell you which required services aren’t running.

      Reply
  10. M.G says

    January 18, 2013 at 7:05 am

    Hi Paul !
    I am one of your fans
    I made a translation to my language and put it on WIKI if you don’t mind
    and i referred it to this page at the end of the wiki post

    http://social.technet.microsoft.com/wiki/contents/articles/15413.exchange-fa-ir.aspx

    Reply
  11. chuck says

    June 7, 2012 at 10:25 pm

    Paul,
    I am having a hard time figuring out how to send this via email. I’ve read your https://www.practical365.com/powershell-how-to-send-email but still can’t get it to work right. Can you post a screen shot of the code with the email part in it?

    Reply
    • Ryan Shaw says

      August 28, 2012 at 5:11 am

      Paul,

      I am too curious to know how to get the last script sent in an email.

      Reply
      • Paul Cunningham says

        September 3, 2012 at 10:22 pm

        I’m working on a more powerful version of this script that does have email capabilities. You can try it out here:

        https://www.practical365.com/powershell-script-health-check-report-exchange-2010

        Reply
  12. Mo says

    March 25, 2012 at 7:10 pm

    Great Post , Just 1 question, how can i get it to write to a txt file and e-mail it to a DL

    Reply
    • Paul Cunningham says

      March 25, 2012 at 7:52 pm

      Hi Mo, you wouldn’t necessarily need to write it to a text file just to be able to email the results.

      I’ve written a series of posts on sending email from scripts so if you go through those you should have no problems creating a script that will email out those results for you.

      https://www.practical365.com/powershell-how-to-send-email

      Reply
      • Mo says

        March 26, 2012 at 10:31 pm

        Thanks Paul

        Reply
  13. Oscar Pedroza says

    March 14, 2012 at 3:20 am

    Excellent post Paul, great job…

    Reply
  14. Kunal says

    October 20, 2011 at 6:13 am

    Worked well, thanks Paul!!

    Reply
    • razzak says

      October 29, 2014 at 3:12 pm

      Excellent , can somebody send me this script .

      Reply

Leave a Reply Cancel reply

You have to agree to the comment policy.

Recent Articles

  • Microsoft Launches Group Ownership Governance Policy
  • Making the Case for Identity Governance in Azure Active Directory
  • Prepare an Office 365 migration plan assessment using PowerShell
  • Microsoft Releases May 2022 Exchange Server Security Updates
  • New Future of Work for Microsoft 365, IOT and more: Practical 365 Podcast S3 Ep. 2

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