Pilu1978
Enthusiast
Enthusiast

VM Snapshot

Jump to solution

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.

0 Kudos
1 Solution

Accepted Solutions
inevp
Enthusiast
Enthusiast

This should print out the names of all the VMs matched by the query:

var vms = Server.findAllForType('VC:VirtualMachine', "xpath:snapshot and sdkId[contains(.,'" + vcname + "')]");

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.

View solution in original post

0 Kudos
6 Replies
inevp
Enthusiast
Enthusiast

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

0 Kudos
Pilu1978
Enthusiast
Enthusiast

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)

0 Kudos
inevp
Enthusiast
Enthusiast

This worked for me:

var vms = Server.findAllForType('VC:VirtualMachine', "xpath:snapshot and sdkId[contains(.,'" + vcname + "')]");

0 Kudos
Pilu1978
Enthusiast
Enthusiast

Thanks a lot.

Sorry to bother you again but how to get the VM name etc from the output it is generating.

0 Kudos
inevp
Enthusiast
Enthusiast

This should print out the names of all the VMs matched by the query:

var vms = Server.findAllForType('VC:VirtualMachine', "xpath:snapshot and sdkId[contains(.,'" + vcname + "')]");

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.

View solution in original post

0 Kudos
Pilu1978
Enthusiast
Enthusiast

Perfect.Thanks a lot.

0 Kudos