How to Use Test-ServiceHealth Cmdlet in Exchange Server?

Exchange Server 2010 and later versions come with a PowerShell command, called Test-ServiceHealth. This PowerShell command is used to test the Exchange Server services and show the services status if they’re running. It will show an error if any service is not running. It is to be noted that this command is not supported on Exchange Server 2013 Client Access Servers. Below, we will see how to use the Test-ServiceHealth command with different parameters.

How to Use the Test-ServiceHealth Cmdlet in Exchange Server?

To run the Test-ServiceHealth command in Exchange Server, you need to ensure that you (the user) have the required rights and permissions. You can run the following command to get the roles that are needed to run this command.

$Perms = Get-ManagementRole -Cmdlet Test-ServiceHealth

run Test-ServiceHealth the following command to get the roles that are needed

After this, run the following command to get the details of the roles needed to run the specified cmdlet.

$Perms | foreach {Get-ManagementRoleAssignment -Role $_.Name -Delegating $false | Format-Table -Auto Role,RoleAssigneeType,RoleAssigneeName}

run Get-ManagementRoleAssignment -Role the following command to get the details of the roles needed to run the specified cmdlet

You need to have the Organization Management, Server Management, and View-Only Organization Management roles. To set these roles and permissions, open the Exchange Admin Center (EAC), click on the Permissions and Admin Roles, and assign accordingly.

Exchange admin center -Permissions-Admin Roles

After assigning the required roles and permissions, you can run the command (as given below) with no parameters or customizations.

Test-ServiceHealth

Test-ServiceHealth

If all the services are running, it will not display anything in the Services Not Running part. If any service is not running, it will display a message mentioning the service which is not running on the server.

display a message mentioning the service which is not running on the server

If you want to run the Test-ServiceHealth command against another server, then you need to specify the ‘Server’ parameter in the command (see the below example).

run the Test-ServiceHealth command against another server

Test-ServiceHealth -Server

The command will show a lot of information. However, if you need only some relevant information, for example, just the status of the services, then you can use the command as given below.

Test-ServiceHealth | ft Role,RequiredServicesRunning -auto

Test-ServiceHealth | ft Role,RequiredServicesRunning

This will show if the services are running or not. If the services are running, the status will be shown as True. If any of the services in the respective role is not running, it will mark it as False for the mailbox role, client access, and hub transport.

If you have more than one server, you can get the test results of all the servers using a single Get-ExchangeServer command (see the below example).

Get-ExchangeServer | Test-ServiceHealth

you can get the test results of all the servers using a Get-ExchangeServer command

To get the summarized report, you can run the following command.

Get-ExchangeServer | Test-ServiceHealth | ft Role,RequiredServicesRunning -auto

to get the summarized report run Get-ExchangeServer | Test-ServiceHealth

If you have several servers, you will not be able to identify which service is associated to which server. For this, you can use the command a little bit different. With Foreach, you can specify the server’s name in the command. The script below will get the same information but will show the associated server name to which the result is related to.

$serverlist = Get-ExchangeServer
Foreach ($server in $serverlist) {Write-Host "Checking" $server.name; Test-ServiceHealth $server | ft Role,RequiredServicesRunning -auto}

Foreach ($server in $serverlist)

As you can see, you can get a lot of information from the Test-ServiceHealth command. In addition, you can also customize the script to get summarized results. The script can be easily adapted to any monitoring and alerting system as well to integrate this to SMS gateways to get prompt message when the problem arises.

Conclusion

There are a lot of things you can prevent but you cannot prevent something you cannot control. When a disaster strikes, it is important to keep the Recovery Point Objective (RPO) and Recovery Time Objective (RTO) to a minimum. The database may get corrupted due to operating system issues, hardware fault, sudden power cut, or virus/malware attacks. In such a case, you can restore exchange database from backup but this will result in data loss.

To reduce the recovery time and point objective and prevent data loss, you can use Exchange recovery tool such as Stellar Repair for Exchange. This tool can repair corrupted or damaged databases of any version of Exchange Server. It scans the databases and then exports the recovered database to PST and other file formats. In case the Exchange Server is re-installed with the same IP address and computer name, you can use Stellar Repair for Exchange to directly export the recovered database to the new live Exchange database. This will drastically reduce the time of recovery as well as reduce the risk of data loss. The application can also export the recovered data directly to Office 365.



Was this article helpful?
About The Author
author image
Shelly Bhardwaj linkdin Icon

Shelly is technology expert and core knowledge of Exchange Server, Outlook.

Table of Contents

WHY STELLAR® IS GLOBAL LEADER

Why Choose Stellar?
  • 0M+

    Customers

  • 0+

    Years of Excellence

  • 0+

    R&D Engineers

  • 0+

    Countries

  • 0+

    PARTNERS

  • 0+

    Awards Received