VMware Cloud Community
Pilu1978
Enthusiast
Enthusiast
Jump to solution

VM Snapshot

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.

Reply
0 Kudos
1 Solution

Accepted Solutions
inevp
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
6 Replies
inevp
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
Pilu1978
Enthusiast
Enthusiast
Jump to solution

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)

Reply
0 Kudos
inevp
Enthusiast
Enthusiast
Jump to solution

This worked for me:

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

Reply
0 Kudos
Pilu1978
Enthusiast
Enthusiast
Jump to solution

Thanks a lot.

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

Reply
0 Kudos
inevp
Enthusiast
Enthusiast
Jump to solution

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.

Reply
0 Kudos
Pilu1978
Enthusiast
Enthusiast
Jump to solution

Perfect.Thanks a lot.

Reply
0 Kudos