Monitoring virtual center server services

If you want to monitor from your management box work of virtual center server, check if services are working, if connection is up, you could use this script.
You can still modify it in different ways. For example if you want to monitor more services, add them in $ServicesToCheck.
I am using an ‘if’ there, as i am not using default services for all vc servers. Email message is build by expanding $emailbody variable. I don’t use smtp authentication here, if you need it, you have to add part with obtaining credentials and passing them to send-mailmessage command.

#if $status will be false, then it will trigger send-mailmessage
#vctomcat           VMware VirtualCenter Management Web...
#vmware-ufad-vci    VMware vSphere Update Manager Service
#vpxd               VMware VirtualCenter Server
#vimQueryService    vCenter Inventory Service
#checking if log file is not too big, if it is , delete 
if(Test-Path $logfile){if ((Get-ChildItem $logfile).length -gt 100KB) { rm $logfile }}
$subject="Virtual center server is down. Investigation is needed!"
$emailbody="Hello,`n`nVirtual center server or its component is down, please investigate!!!`n`n"

Monitoring Script
foreach ($vc in $vcservers)
	$emailbody+="`n`nVirtual Center server: ${vc}`n"
		if ($testcon=Test-Connection $vc -ErrorAction SilentlyContinue){
			$emailbody+="`n Test-connection from mgmt box to $VC is OK.`n"
			if($vc -eq "server1"){$ServicesToCheck="vctomcat","vpxd","vimQueryService"}
			if($vc -eq "serverN"){$ServicesToCheck="vmware-ufad-vci","vctomcat","vpxd"}
				foreach($service in $ServicesToCheck){
					if($qservice=Get-Service $service -ComputerName $vc -ErrorAction SilentlyContinue){
						if($qservice.status -ne 'Running'){
							$emailbody+="`nService $($ is not running`n"
							$emailbody+="`nService $($ is running`n"
					}else {
						$emailbody+="`nCould not query service: ${service}`n"	
		}else {
			$emailbody+="`n Test-connection from mgmt box to $VC has failed, please check whether VC server is up and network is working.`n"
Send-MailMessage -Subject $subject -From $SMTPfrom -SmtpServer $SMTPserver -To $SMTPto -Body  $emailbody
"VC IS DOWN at $(get-date)" >> "c:\scripts\vc_monitoring\vcmonitoring.log"

Make sure that the user from which this script will run, has proper rights on target VC server. If he is missing rights then the get-service will not work.