Function: vCenter Host System Service 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: ServiceStart

publicServiceStart(objVcHostSystem:VcHostSystem,strServiceName:string):boolean{

letblnReturn:boolean=this.ServiceToggle(objVcHostSystem,strServiceName,"Start");

returnblnReturn;
}
TypeScript

Public Function: ServiceStop

publicServiceStop(objVcHostSystem:VcHostSystem,strServiceName:string):boolean{

letblnReturn:boolean=this.ServiceToggle(objVcHostSystem,strServiceName,"Stop");

returnblnReturn;
}
TypeScript

Public Function: ServiceRestart

publicServiceRestart(objVcHostSystem:VcHostSystem,strServiceName:string):boolean{

letblnReturn:boolean=this.ServiceToggle(objVcHostSystem,strServiceName,"Restart");

returnblnReturn;
}
TypeScript

Private Function: ServiceToggle

privateServiceToggle(objVcHostSystem:VcHostSystem,strServiceName:string,strServiceStatus:"Start"|"Stop"|"Restart"):boolean{

try{
letobjVcHostConfigManager:VcHostConfigManager=objVcHostSystem.configManager;

letobjVcHostServiceSystem:VcHostServiceSystem=objVcHostConfigManager.serviceSystem;

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

this.objLogger.info(`Attempting to${strServiceStatus} Service on host: '${objVcHostSystem.name}'...`);

if (objVcHostService.running===true&&strServiceStatus==="Restart"){
objVcHostServiceSystem.restartService(strServiceName);
}elseif (objVcHostService.running===true&&strServiceStatus==="Stop"){
objVcHostServiceSystem.stopService(strServiceName);
}elseif (objVcHostService.running===false&&strServiceStatus==="Start"){
objVcHostServiceSystem.startService(strServiceName);
}

this.objLogger.info(`Succesfully${strServiceStatus}ed Service on host: '${objVcHostSystem.name}'.`);

returntrue;
}
catch (objException){

this.objLogger.info(`Failed to${strServiceStatus} Service on host: '${objVcHostSystem.name}'.`);

returnfalse;
}
}
TypeScript

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like