Monitoring virtual center server services

by Grzegorz Kulikowski

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.
[sourcecode language=”powershell”]
#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,nnVirtual center server or its component is down, please investigate!!!nn"

Monitoring Script
foreach ($vc in $vcservers)
$emailbody+="nnVirtual Center server: ${vc}n"
if ($testcon=Test-Connection $vc -ErrorAction SilentlyContinue){
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'){
nService $($ is not runningn"
nService $($ is runningn"
}else {
nCould not query service: ${service}n"
}else {
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.

You may also like

Leave a Reply

Chinese (Simplified)EnglishFrenchGermanHindiPolishSpanish
Streaming live on Twitch right now.