Skip to content

Instantly share code, notes, and snippets.

@vmwarecode
Created November 22, 2015 02:54
Show Gist options
  • Save vmwarecode/3e81d82714c7ad6ced15 to your computer and use it in GitHub Desktop.
Save vmwarecode/3e81d82714c7ad6ced15 to your computer and use it in GitHub Desktop.
Find vSphere VM by Name across all vCenters in vRealize Orchestrator
//action Inputs:
// vmName - string
//
//Return Type: VC:VirtualMachine
var found = VcPlugin.getAllVirtualMachines(null, "xpath:name[matches(.,'"+vmName+"')]");
if (found.length > 1) {
throw(vmName+" matched more than one Virtual Machine");
}
if (found.length == 1) {
return found[0];
}
throw("Virtual Machine does not exist by name: "+vmName);
@bbusoi
Copy link

bbusoi commented Jun 17, 2022

The search is case sensitive, for case insensitive search use getAllVirtualMachines(null, "xpath:matches(name, '(?i)" + vmName + "')");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment