Listing the health status of management servers
The following code demonstrates how to get the health status of management servers. The code will read the status of all management servers in the environment and display the status message. In an environment where all the management servers are healthy, the code will write a generic message that all the management servers are healthy. We can also generate the output in the form of a report:
$MSUnhealthCount = Get-SCOMManagementServer | where {$_.HealthState -ne "Success"} | Measure-Object if($MSUnhealthCount .Count -gt 0) { $UnHealthyMS = Get-SCOMManagementServer | where {$_.HealthState -ne "Success"} | select DisplayName,HealthState,IsGateway $UnHealthyMS } Else { Write-Host "All management servers are in healthy state" }