VMware Cloud Community
jacquesperrin
Enthusiast
Enthusiast
Jump to solution

How to get vRA VMs name where a specific custom property name does not exists

Hi all

I would like to search the VMs whose haven't a specific custom property defined on it.

Anyone have a idea to do that in only one Odata query ? (to avoid looking 4000 Vms one by one)

I found this link to find the Vms by custom property name and value (https://automate-it.today/vro-code-finding-virtualmachines-custom-property/)

But in my case, it's a little bit different, because  i want to get VM name if a custom property not exist.

Thanks for your help

Jacques

1 Solution

Accepted Solutions
stevedrummond
Hot Shot
Hot Shot
Jump to solution

Change your query to:

var filter = "not(VirtualMachineProperties/any(p: p/PropertyName eq '" + propertyName + "')) and IsManaged eq true";

That will give you all the entities that are managed by this vRA and which do not contain a property with that name. You can then get all the names with:

const names = machines.map(function(machine) {     return machine.getProperty("VirtualMachineName"); });

View solution in original post

1 Reply
stevedrummond
Hot Shot
Hot Shot
Jump to solution

Change your query to:

var filter = "not(VirtualMachineProperties/any(p: p/PropertyName eq '" + propertyName + "')) and IsManaged eq true";

That will give you all the entities that are managed by this vRA and which do not contain a property with that name. You can then get all the names with:

const names = machines.map(function(machine) {     return machine.getProperty("VirtualMachineName"); });