VMware Cloud Community

nested xpath expression | retrieve all VMs that are defined as templates

I am trying to retrieve all VM templates that exist within the vCenter Server.

Assuming that I am using the following code:

var VcVirtualMachine_Array = Server.findAllForType("VC:VirtualMachine",XPath_query);

what should be the XPath_query value ?

I already tried the following methods:

var XPath_query = "xpath:isTemplate='true'";

var XPath_query = "xpath:config.template[contains(.,'true')]";

var XPath_query = "xpath://config/template[@name='template' and @type='true']";

also , according to the following link:


the Finder type: VC:VirtualMachine

has a Property named isTemplate

but I am not able to filter the output using this type of Property.

what is the way to filter using XPath a nested attribute ?

because the object it's self has an attribute named: config.template

but all of them were not helping to achieve what I am looking to retrieve as already filtered output.

thank in advanced for the assistance

0 Kudos
1 Reply
VMware Employee
VMware Employee


Try with:

var XPath_query = "xpath:config/template[ . = true() ]";

var VcVirtualMachine_Array = Server.findAllForType("VC:VirtualMachine", XPath_query);