Function: vCenter Virtual Machine Get the Current Value of a Custom Attribute

by Simon Sparks · 15 February 2022

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

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

Filename: vCenterService.ts

Function VcVirtualMachineCustomAttributeValueGet

Description: Orchestrator Function to Get the Current Value of a Custom Attribute

public VcVirtualMachineCustomAttributeValueGet(objVcVirtualMachine: VcVirtualMachine, strVcCustomFieldName: string): string {
    let objVcSdkConnection: VcSdkConnection = objVcVirtualMachine.vimHost;

    let objVcCustomFieldsManager: VcCustomFieldsManager = objVcSdkConnection.customFieldsManager;

    let arrVcCustomFieldDef: VcCustomFieldDef[] = objVcCustomFieldsManager.field;

    let objVcCustomFieldDef: VcCustomFieldDef = arrVcCustomFieldDef.find((objVcCustomFieldDef: VcCustomFieldDef): boolean => {
        return objVcCustomFieldDef.name === strVcCustomFieldName;
    });

    let arrVcCustomFieldValue: VcCustomFieldValue[] = objVcVirtualMachine.customValue;

    let objCustomFieldValue: VcCustomFieldValue = arrVcCustomFieldValue.find((objVcCustomFieldValue: VcCustomFieldValue): boolean => {
        return objVcCustomFieldValue.key === objVcCustomFieldDef.key;
    });

    //@ts-ignore
    let strReturnValue: string = objCustomFieldValue.value;

    return strReturnValue;
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like