vCO – Configure NTP on ESX

In this example I set the NTP Server and then check if the NTP Service is running. If not I start it.

//myhost is input parameter of type VcHostSystem
//ntpServer is input parameter of type String[] (string array)

var hostDateTimeConfig = new VcHostDateTimeConfig();
hostDateTimeConfig.ntpConfig = new VcHostNtpConfig();
hostDateTimeConfig.ntpConfig.server = ntpServer;

//Set the ntp servers

//Check if the service is already running
var hostServiceInfo = myhost.configManager.serviceSystem.serviceInfo;
for each (var hostService in hostServiceInfo.service)
if (hostService.label == “NTP Daemon”)
//if the service is not running start it
if (hostService.running == false)
System.log(“Starting service ” + hostService.label + ” now”);
var ntpID =;
System.log(“Service ” + hostService.label + ” is already running”);

Published by txusa

VMware Certified Design Expert - VCDX 92. VMware Architect, automation enthusiast.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: