Hi community ,
i am searching for a way to know what is the power state of the VM when a snapshot taken .
vcenter 6.5
thanks in advance
Hi, and welcome to the community.
Take a look at the scripting action com.vmware.library.vc.vm.snapshot/getAllSnapshotsOfVM. It enumerates all snapshots of a VM. The state of the VM when a particular snapshot was taken is stored in the snapshot tree object, so you can easily fetch it from the variable state.
Something like the following should print all snapshot names for the given VM referenced by the variable vm, together with the state of the VM when each snapshot was taken (the difference from the original scripting action code is only line 11 being added)
var snapshots = new Array();
if(vm.snapshot){
var snapshotTrees = vm.snapshot.rootSnapshotList;
for (i in snapshotTrees){
getSnapshotsOfVM(snapshotTrees[i]);
}
}
return snapshots;
function getSnapshotsOfVM(tree) {
System.log("Snapshot name: " + tree.name + " VM state: " + tree.state);
snapshots.push(tree.snapshot);
var trees = tree.childSnapshotList;
if (trees != null) {
for (index in trees) {
if (trees[index] != null)
getSnapshotsOfVM(trees[index]);
}
}
}
I think i misunderstood the question. Please follow the suggestion given below by Ilian Iliev.
You can not have two active task on a VM at any given point of time.
While taking the snapshot either the VM is up or down.
Nevermind if the VM is down. You can tail on the vmware.log located in the virtual machine working directory while take snapshot task is in progress.
Change in power state will be shown in the logs. Power state change might happen because of BSOD or kernel panic etc.
If you found this or any other answer helpful, please consider the use of the Correct or Helpful to award points.
Best Regards,
Deepak Koshal
CNE|CLA|CWMA|VCP4|VCP5|CCAH
Hi, and welcome to the community.
Take a look at the scripting action com.vmware.library.vc.vm.snapshot/getAllSnapshotsOfVM. It enumerates all snapshots of a VM. The state of the VM when a particular snapshot was taken is stored in the snapshot tree object, so you can easily fetch it from the variable state.
Something like the following should print all snapshot names for the given VM referenced by the variable vm, together with the state of the VM when each snapshot was taken (the difference from the original scripting action code is only line 11 being added)
var snapshots = new Array();
if(vm.snapshot){
var snapshotTrees = vm.snapshot.rootSnapshotList;
for (i in snapshotTrees){
getSnapshotsOfVM(snapshotTrees[i]);
}
}
return snapshots;
function getSnapshotsOfVM(tree) {
System.log("Snapshot name: " + tree.name + " VM state: " + tree.state);
snapshots.push(tree.snapshot);
var trees = tree.childSnapshotList;
if (trees != null) {
for (index in trees) {
if (trees[index] != null)
getSnapshotsOfVM(trees[index]);
}
}
}
thank you so much .
also you can use get-snapsho command .
hi ;
We found another easy way to get the information , this time it is from RV tools
Go to vSnapshot , column State
State The power state of the virtual machine when this snapshot was taken.
You can found out more from RV tools document page 40