Hi llian,
could you tell what is the equivalent in java script for the folowing line .
$x= get-vm|where-object{$_.powerstate -eq "poweredoff}
.poweredon also need to be .poweredOn
It looks like this PowerCLI script gets list of VMs that are powered off.
An equivalent in vRO Javascript could be something like the following:
// Get list of powered-off VMs
var poweredOffVMs = VcPlugin.getAllVirtualMachines().filter(function(vm) {
return vm.runtime.powerState == VcVirtualMachinePowerState.poweredOff;
});
// Print their names
for each (vm in poweredOffVMs) {
System.log("vmname: " + vm.name);
}
Thanks.I am checking this.
hi llian ,
the code which u mentioned prints the list of all vms in vcenter not the poweredoff .
also could you tell me what is the use of "return" in this code/
OK, let's got over the code step by step:
VcPlugin.getAllVirtualMachines() returns an array with all virtual machines.
filter(somefunction) applies the boolean function somefuction to all elements of the array one by one, and returns a new array with those elements from the original array for which the function evaluates to true
return vm.runtime.powerState == VcVirtualMachinePowerState.poweredOff; is an expression that returns true or false depending on whether the powerState property has value poweredOff or not.
Combining the above, the code on lines 1..4 returns those virtual machines that has their powerState property set to poweredOff
Thanks .i am checking again why it is printing the entire list of vms in Vcenter .
Could you check what happens if you replace poweredOff with poweredOn (to get the list of powered on vms)?
Hi llian,
good morning
i did to find powered on vms as per following code
but got folliwing error ;
The code contains a typo; the method getAllVirtualMAchines() should be getAllVirtualMachines with lowercase 'a' in word Machines
it has run successfully but for some resons not printing the names. though we have
System.log ........
i am doing this on vmware hands on lab hope that does not make any difference .
.poweredon also need to be .poweredOn
Thanks .I need to remeber again that java script is case sensitive.
it worked fine .