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 + "')");

@kbranvh
Copy link

kbranvh commented Aug 22, 2024

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

Thank you sir. just what I needed

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