Skip to content

Instantly share code, notes, and snippets.

@dlinsley
Created October 26, 2018 22:31
Show Gist options
  • Save dlinsley/7da40e12eee1d73083d48545bdc7ec5e to your computer and use it in GitHub Desktop.
Save dlinsley/7da40e12eee1d73083d48545bdc7ec5e to your computer and use it in GitHub Desktop.
Get vSphere Datastore by name
// VMware vRealize Orchestrator action sample
// Searches a vCenter or all known vCenters for a Datastore
//
// ensures the search only matches one Datastore
//
//Action Inputs:
// vCenter - VC:SdkConnection (Optional)
// datastoreName - String
//
//Return type: VC:StoragePod
var found;
if (vCenter) {
found = vCenter.getAllDatastores(null, "xpath:info/name[matches(.,'" + datastoreName + "')]");
} else {
found = VcPlugin.getAllDatastores(null, "xpath:info/name[matches(.,'" + datastoreName + "')]");
}
if (found.length > 1) {
throw(datastoreName+" matched more than one datastore");
}
if (found.length == 0) {
throw(datastoreName+" datastore does not exist");
}
return found[0];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment