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.