Some small additions to filter the value directly in the query and optionally get all the properties for the vm results
function findVirtualMachinesWithPropertyValue(vcacHost, propertyName, propertyValue, getProperties) { return vCACEntityManager.readModelEntitiesBySystemQuery( vcacHost.id, "ManagementModelEntities.svc", "VirtualMachineProperties", "PropertyName eq '" + propertyName + "' and PropertyValue eq '" + propertyValue + "'" ).reduce(function (vms, propertyEntity) { // get the VirtualMachineEntity var virtualMachine = propertyEntity.getLink(vcacHost, "VirtualMachine").shift() var result = { vm: virtualMachine, properties: new Properties() } // optionally create a properties object containing the vms properties if (getProperties) { virtualMachine.getLink(host, "VirtualMachineProperties").forEach(function (prop) { result.properties.put(prop.getProperty("PropertyName"), prop.getProperty("PropertyValue")) }) } return vms.concat(result) }, []) }
Called like
var results = findVirtualMachinesWithPropertyValue(host, "__Cafe.Root.Request.Id", "some-uuid-here", true)
each result contains the vm entity and properties