vspherevmware-tools

How do i filter using a partial VM name (string) in vmware vSphere client REST API?


Good day!

i am trying to automate some actions to be done to VM's in my organisation. The action to be done depends on the a substring in the VM name.

for eg, i would need to delete all VM's whose name starts with 'delete', etc.

I can use the below API to fetch the list of VM's:

GET https://{{vc}}/rest/vcenter/vm

However, this API can only fetch a maximum of 1000 VM's.

Is there any way i can filter and get only the list of VM's with the expected substring from this API?

from what i understand, appending filter.names.1 to the above API works but for that i need to input the exact and entire VM name.

is there a way where i can search for a list of VM's with partial text?

Apologies, i am a newbie to this.

thank you for your time!


Solution

  • Unfortunately the vSphere Automation API isn't setup to filter on partial names or even when using a wildcard. Some of the available filters may help you limit the output to be under the 1000 object limit (example: filter on specific clusters and/or folders).

    Hopefully this is something that's added in a future release.