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
myhost.configManager.dateTimeSystem.updateDateTimeConfig(hostDateTimeConfig);
//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 = myhost.configManager.dateTimeSystem.id;
host.configManager.serviceSystem.startService(“ntpd”);
}
else
{
System.log(“Service ” + hostService.label + ” is already running”);
}
}
}