When you invoke a finder method, you can use expressions based on the XPath query language. The search returns all the inventory objects that match the XPath expressions. If you want to query for any properties, you can include them to the search script in the form of a string array.

The following JavaScript example uses the VcPlugin scripting object and an XPath expression to return the names of all datastore objects that are part of the vCenter managed objects and contain the string ds in their names.

var datastores = VcPlugin.getAllDatastores(null, "xpath:name[contains(.,'ds')]");
for each (datastore in datastores){
     System.log(datastore.name); 
 }

The same XPath expression can be invoked by using the Server scripting object and the findAllForType finder method.

var datastores = Server.findAllForType("VC:Datastore", "xpath:name[contains(.,'ds')]");
for each (datastore in datastores){
     System.log(datastore.name); 
 }

The following script example returns the names of all host system objects whose ID starts with the digit 1.

var hosts = VcPlugin.getAllHostSystems(null, "xpath:id[starts-with(.,'1')]");
for each (host in hosts){
     System.log(host.name); 
}

The following script returns the names and IDs of all data center objects that contain the string DC, in upper- or lower-case letters, in their names. The script also retrieves the tag property.

var datacenters = VcPlugin.getAllDatacenters(['tag'], "xpath:name[contains(translate(., 'DC', 'dc'), 'dc')]");
for each (datacenter in datacenters){
     System.log(datacenter.name + " "  +  datacenter.id); 
}