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

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

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

    return blnReturn;
}
TypeScript

Public Function: ServicePolicyDisable

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

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

    return blnReturn;
}
TypeScript

Private Function: ServicePolicyToggle

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

    try {
        let objVcHostConfigManager: VcHostConfigManager = objVcHostSystem.configManager;

        let objVcHostServiceSystem: VcHostServiceSystem = objVcHostConfigManager.serviceSystem;

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

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

        return true;
    }
    catch (objException) {
        return false;
    }
}
TypeScript

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like