Some times you get a requirement where you have to monitor a service/process if it is running i.e. monitor and tell me if this service is running and if it is not running then everything is fine. Also turn the status of the application template into green colour if service is stopped and turn it red if it is running. Below is the custom power shell script that can be applied on the windows machine whose services need to be monitored as in above mentioned scenarios.
*****************************************************************************
$a="Running"
$stat=Get-Service "Service_Name"
$c=$stat.status
if ($c -eq $a){
write-host "Statistic: 1";
Write-host "Message: Service is $c";
exit 3;
}
else{
write-host "Statistic: 0";
Write-host "Message: Service is $c";
exit 0;
}
******************************************************************************
Remove double quotes above while giving the exact service name. You can also use arguments if there are multiple services to monitor.