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.
[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:
[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:
[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:
[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.
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.
#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.
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.
[adrotate banner=”48″]
Thank you Paul. very useful
Pingback: [Tutoriel] Installer les Rollup sur Exchange Server 2010
Thank you PAUL!!! I LOVE YOU!! Needed to see which exact service was not running, so glad for this.
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
The Real Person!
The Real Person!
Test-ServiceHealth is expect it to be running. In the past I’ve simply enabled and started the service.
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
The Real Person!
The Real Person!
This should help:
https://www.practical365.com/testing-exchange-server-2013-client-access-server-health-with-powershell/
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
The Real Person!
The Real Person!
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
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
The Real Person!
The Real Person!
There’s a Start-Service cmdlet in PowerShell, or you can use the Services.msc console.
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
The Real Person!
The Real Person!
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.
Got you Paul. Thanks a lot.
Best Regards,
Krish
Hi Paul,
this is a great script. Is there any fix for the EdgeSync failure in report available ?
Thanks a lot
The Real Person!
The Real Person!
Start the service?
Pingback: Turning to a PAL when troubleshooting Exchange… |
Pingback: List of the commands to fast troubleshoot Microsoft Exchange | Powershell.Az Blog - let's scripting..
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
The Real Person!
The Real Person!
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.
Hi,
If there I get
Role : Client Access Server Role
RequiredServicesRunning : False
How to make it to true?
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.
Pingback: MSExchange EdgeSync Service Won't Start and Event ID 1045 is Logged
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
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?
Paul,
I am too curious to know how to get the last script sent in an email.
The Real Person!
The Real Person!
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
Great Post , Just 1 question, how can i get it to write to a txt file and e-mail it to a DL
The Real Person!
The Real Person!
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
Thanks Paul
Excellent post Paul, great job…
Pingback: Test-MailboxServer - Health Check an Exchange 2010 Mailbox Server
Worked well, thanks Paul!!
Excellent , can somebody send me this script .