Function: vCenter Host System Service Policy Toggle

by Simon Sparks · 23 March 2026

To use this function add it to the class library file named PluginVCHostSystemService.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: PluginVCHostSystemService.ts

Public Function: ServicePolicyEnable

publicServicePolicyEnable(objVcHostSystem:VcHostSystem,strServiceName:string,strServicePolicyState:"on"|"off"):boolean{

letblnReturn:boolean=this.ServicePolicyToggle(objVcHostSystem,strServiceName,"on");

returnblnReturn;
}
TypeScript

Public Function: ServicePolicyDisable

publicServicePolicyDisable(objVcHostSystem:VcHostSystem,strServiceName:string,strServicePolicyState:"on"|"off"):boolean{

letblnReturn:boolean=this.ServicePolicyToggle(objVcHostSystem,strServiceName,"off");

returnblnReturn;
}
TypeScript

Private Function: ServicePolicyToggle

privateServicePolicyToggle(objVcHostSystem:VcHostSystem,strServiceName:string,strServicePolicyState:"on"|"off"):boolean{

try{
letobjVcHostConfigManager:VcHostConfigManager=objVcHostSystem.configManager;

letobjVcHostServiceSystem:VcHostServiceSystem=objVcHostConfigManager.serviceSystem;

letobjVcHostService:VcHostService=this.ServiceGetByName(objVcHostServiceSystem,strServiceName);

if (objVcHostService.policy==="on"&&strServicePolicyState==="off"){
objVcHostServiceSystem.updateServicePolicy(strServiceName,"off");
}elseif (objVcHostService.policy==="off"&&strServicePolicyState==="on"){
objVcHostServiceSystem.updateServicePolicy(strServiceName,"on");
}

returntrue;
}
catch (objException){
returnfalse;
}
}
TypeScript

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like