Share

Code Snippet: Get VM (Vc:VirtualMachine) using MoRefId in Orchestrator

by Mayank Goyal · 5 Dec 2025
/**
 *
 * @module mayank.actions
 *
 * @version 1.0.0
 *
 * @param {string} morefId VM MorefId to find eg. vm-3021
 * @param {string} vc vCenter FQDN eg. vcenter.vcf.lab
 *
 * @outputType Array/VC:VirtualMachine
 *
 */
function getVmByMorefIdorId(morefId, vc) {
	if (vc) {
		var myVcPlugin = VcPlugin.allSdkConnections ;
		for each (var vcplug in myVcPlugin){
			var vcname = vcplug.name
			vcname = vcname.replace(':443/sdk','')
			vcname = vcname.replace('https://','')
			if (vcname == vc){
			break}
			}
		}
		else {
			var vcplug = VcPlugin
			}
	System.log(vcplug)
	
	
	
	vms = new Array();
		var found = vcplug.getAllVirtualMachines(null, "xpath:id[translate(.,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='" + morefId.toUpperCase() + "']");
		System.log(found)
		for (var j in found) {
			vms.push(found[j]);
		}
	return vms;
}
Input fields for VM MorefId and vCenter FQDN with RUN and CANCEL buttons below.
Screenshot of a coding interface showing inputs and action results for the function getVmByMorefIdorId, including parameters like morefId and vc.
A screenshot of the vSphere Client interface displaying the summary of a virtual machine named 'LX-TE-ST-01'. The left panel shows a tree structure of virtual machines, while the right panel presents details including the guest OS, power status, and options to launch a remote console.

Discover more from Cloud Blogger

Subscribe to get the latest posts sent to your email.

You may also like