VMware Cloud Community
jamesreinke2
Enthusiast
Enthusiast
Jump to solution

Search for VM

Being new to vRO im slowly getting a grasp on understanding the workflows. What escapes me is if I put out something in the XaaS lets say for a snapshot the user can see and do a snapshot for anything VM in vcenter. Is there a way to search for VMs within a folder in vcenter or give a listing of vms with a particular prefix. If there is something out there that would be great but being new I would need the whole workflow unless any of you can give exact instructions.

Thanks in advance

Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Here is some code to print the names of VMs within a given VmFolder (input parameter is variable folder of type VC:VmFolder)

for each (var vm in folder.vm) {

  System.log(vm.name);

}

Here is some code to print the names of all VMs whose name starts with a given prefix:

var prefix = 'myvm';

var vms  = VcPlugin.getAllVirtualMachines(null, "xpath:name[starts-with(.,'" + prefix +"')]");

for each (var vm in vms) {

  System.log(vm.name);

}

View solution in original post

Reply
0 Kudos
2 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Here is some code to print the names of VMs within a given VmFolder (input parameter is variable folder of type VC:VmFolder)

for each (var vm in folder.vm) {

  System.log(vm.name);

}

Here is some code to print the names of all VMs whose name starts with a given prefix:

var prefix = 'myvm';

var vms  = VcPlugin.getAllVirtualMachines(null, "xpath:name[starts-with(.,'" + prefix +"')]");

for each (var vm in vms) {

  System.log(vm.name);

}

Reply
0 Kudos
jamesreinke2
Enthusiast
Enthusiast
Jump to solution

Ilian

Thank you. Its so simple when someone shows you how. Next is for me to get some training but there doesn't seem to be much out there.

James

Reply
0 Kudos