Hi Guys,
What is the quickest way to get the list of VM's which are having snapshot on a VC. I have written one such which scans each VM for snapshots and takes hell lot of time to complete.
This should print out the names of all the VMs matched by the query:
for (var i = 0; i < vms.length; i++) {
System.log(vms[i].name);
}
Note that vcname should be the whole text or a part of what you put for "IP or host name of the vCenter Server instance to add" in the "Add a vCenter Server Instance" workflow when you added your vCenters to vRO that uniquely identifies the vcenter which you want to query.
You can try using a XPath query like:
var vms = Server.findAllForType('VC:VirtualMachine', 'xpath:snapshot');
For more information see: Using XPath Expressions with the vCenter Server Plug-In
Thanks for your reply.
I am getting the following output. Sorry but I am new to vRO so if you could tell me how to get the VM name, snapshot creation date etc from the following output. My vRO instance is connected to 5 VCs. if I want to run against one VC then what will be the syntax.
[2020-05-15 08:07:59.903] [I] DynamicWrapper (Instance) : [VcVirtualMachine]-[class com.vmware.o11n.plugin.vsphere_gen.VirtualMachine_Wrapper] -- VALUE : Stub: moRef = (ManagedObjectReference: type = VirtualMachine, value = vm-2612, serverGuid = null), binding = https://vcenter.com:443/sdk,DynamicWrapper (Instance) : [VcVirtualMachine]-[class com.vmware.o11n.plugin.vsphere_gen.VirtualMachine_Wrapper] -- VALUE : Stub: moRef = (ManagedObjectReference: type = VirtualMachine, value = vm-44533, serverGuid = null), binding = https://vcenter.com:443/sdk,DynamicWrapper (Instance)
This worked for me:
var vms = Server.findAllForType('VC:VirtualMachine', "xpath:snapshot and sdkId[contains(.,'" + vcname + "')]");
Thanks a lot.
Sorry to bother you again but how to get the VM name etc from the output it is generating.
This should print out the names of all the VMs matched by the query:
for (var i = 0; i < vms.length; i++) {
System.log(vms[i].name);
}
Note that vcname should be the whole text or a part of what you put for "IP or host name of the vCenter Server instance to add" in the "Add a vCenter Server Instance" workflow when you added your vCenters to vRO that uniquely identifies the vcenter which you want to query.
Perfect.Thanks a lot.