Orchestrator Function: vCenter VAPI Plugin Check if Tag Exists in All vCenters

by Simon Sparks · 13 January 2026

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

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

Filename: vCenterVAPIService.ts

Type vCenterServer

type vCenterServer={
    Name:string;
    Environment: Environment;
    vCenterType: vCenterType;
    Location: ServerLocation;
    Priority: ServerPriority;
    Secret:string;
    vCenterAssociation:string[];
};

enum vCenterType{
Management="Management",
Workload="Workload"
}

enum ServerLocation{
SiteEast="Site East",
SiteWest="Site West",
SiteStretched="Site Stretched"
}

enum ServerPriority{
Primary="Primary",
Secondary="Secondary"
}

Function isTagExistsInAllVCenterServers

Explanation: arrVCenterServers is an array of the type vCneterServer and it contains a static list of all vCenters and is maintained in the Constants.ts file of the project so that it can be used by any function that needs it.

publicisTagExistsInAllVCenterServers(strTagName:string,strTagCategoryName:string):boolean{
letblnResult:boolean=true;

this.objLogger.info(`Start - Checking if Tag '${strTagName}' exists in all vCenter Servers`);

this.arrVCenterServers.forEach((objVCenterServer:vCenterServer):void=>{
letstrVCenterServerName:string=objVCenterServer.Name;

letobjVAPIClient:VAPIClient;

try{
letobjVAPIEndpoint:VAPIEndpoint=VAPIManager.findEndpoint(`https://${strVCenterServerName}/api`);

objVAPIClient=objVAPIEndpoint.client(null,null);

letstrTagCategoryID:string=this.findTagCategoryIDByName(objVAPIClient,strTagCategoryName);

this.objLogger.info(`===== vCenter Server = '${strVCenterServerName}' for Tag Category Name = '${strTagCategoryName}' - Checking`);

if (strTagCategoryID){
this.objLogger.info(`===== vCenter Server = '${strVCenterServerName}' for Tag Category Name = '${strTagCategoryName}' - Found`);

letstrTagID:string=this.findTagIDByNameFromSpecificCategoryID(objVAPIClient,strTagName,strTagCategoryID);

if (strTagID){
this.objLogger.info(`===== vCenter Server = '${strVCenterServerName}' for Tag Category Name '${strTagCategoryName}' and Tag Name '${strTagName}' - Found.`);
}else{
blnResult=false;

this.objLogger.warn(`===== vCenter Server = '${strVCenterServerName}' for Tag Category Name = '${strTagCategoryName}' and Tag Name '${strTagName}' - Not Found.`);
}
}
else{
blnResult=false;

this.objLogger.warn(`===== vCenter Server = '${strVCenterServerName}' for Tag Category Name = '${strTagCategoryName}' - Not Found`);
}
}catch (objException){
blnResult=false;

this.objLogger.info(`End - Checking if Tag '${strTagName}' exists in all vCenter Servers failed`);
}finally{
objVAPIClient.close();

this.objLogger.info(`End - Checking if Tag '${strTagName}' exists in all vCenter Servers completed with result${blnResult}.`);
}
});

returnblnResult;
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like