KB: Get the HealthState of a monitor in Powershell

How to get the HealthState of a VMware Virtual Machine by making use of Powershell

$class = Get-SCOMClassInstance -DisplayName "<Virtual Machine Name>" 

$monitor = Get-SCOMMonitor -DisplayName "Virtual Machine VMware Tools Status" 

$monitorInstances = New-Object "System.Collections.Generic.List[Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitor]" 

$monitorInstances.add($monitor) 

$state= $class.getmonitoringstates($monitorInstances)