Orchestrator Function: vCenter Virtual Machine Storage DRS Anti Affinity Get All and Get by Name

by Simon Sparks · 25 January 2026

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

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

Filename: vCenterServerService.ts

Description: Orchestrator Function to Get Storage DRS Settings for a vCenter Virtual Machine

Function StorageDrsAntiAffinityGetAll

privateStorageDrsAntiAffinityGetAll(objVcStoragePod:VcStoragePod):VcStorageDrsVmConfigInfo[]{

letobjVcPodStorageDrsEntry:VcPodStorageDrsEntry=objVcStoragePod.podStorageDrsEntry;

letobjVcStorageDrsConfigInfo:VcStorageDrsConfigInfo=objVcPodStorageDrsEntry.storageDrsConfig;

letarrVcStorageDrsVmConfigInfo:VcStorageDrsVmConfigInfo[]=objVcStorageDrsConfigInfo.vmConfig;

returnarrVcStorageDrsVmConfigInfo;
}

Function: StorageDrsAntiAffinityGetByStatus

publicStorageDrsAntiAffinityGetByStatus(objVcStoragePod:VcStoragePod,blnEnabled:boolean=true):VcStorageDrsVmConfigInfo[]{

letarrVcStorageDrsVmConfigInfo:VcStorageDrsVmConfigInfo[]=this.StorageDrsAntiAffinityGetAll(objVcStoragePod);

arrVcStorageDrsVmConfigInfo=arrVcStorageDrsVmConfigInfo.filter((objVcStorageDrsVmConfigInfo:VcStorageDrsVmConfigInfo):boolean=>{
returnobjVcStorageDrsVmConfigInfo.enabled=blnEnabled;
});

returnarrVcStorageDrsVmConfigInfo;
}

Function: StorageDrsAntiAffinityGet

publicStorageDrsAntiAffinityGet(objVcStoragePod:VcStoragePod,strVcClusterAntiAffinityRuleSpecName:string):VcStorageDrsVmConfigInfo{

letarrVcStorageDrsVmConfigInfo:VcStorageDrsVmConfigInfo[]=this.StorageDrsAntiAffinityGetAll(objVcStoragePod)

letobjVcStorageDrsVmConfigInfo:VcStorageDrsVmConfigInfo=arrVcStorageDrsVmConfigInfo.find((objVcStorageDrsVmConfigInfo:VcStorageDrsVmConfigInfo):boolean=>{

letobjVcVirtualDiskAntiAffinityRuleSpec:VcVirtualDiskAntiAffinityRuleSpec=objVcStorageDrsVmConfigInfo.intraVmAntiAffinity;

objVcStorageDrsVmConfigInfo.intraVmAffinityDisks

returnobjVcVirtualDiskAntiAffinityRuleSpec.name===strVcClusterAntiAffinityRuleSpecName;
});

returnobjVcStorageDrsVmConfigInfo;
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like