I am trying to get virtual mchinesnames using vRO.
created following workflow.
put following code in scriptable task
var virtualmachines = VcPlugin.getAllVirtualMachines();
for each (virtualmachine in virtualmachines);
{
System.log("virtualmachine :" + virtualmachine.name);
}
However it is giving me only one virtual machine name .
please suggest what is the issue.
Hi,
The issue is that there is a semicolon character at the end of the loop definition and before its body:
for each (virtualmachine in virtualmachines);
it should be
for each (virtualmachine in virtualmachines)
Thanks it worked however during validation it did not throw error even there was semicoloneafter for each bracket.
Yes, because it is a valid Javascript code - a loop with no body, and a single scoped statement after it.
Thnaks.i also thought of utilizing another property of VcVirtualMachine object .one of them is guest .
So i added additional code in blue shade.
var virtualmachines = VcPlugin.getAllVirtualMachines();
for each (virtualmachine in virtualmachines)
{
System.log("virtualmachine :" + virtualmachine.name + " vmguest :" + virtualmachine.guest);
}
but output i got is not in proper format as happened with name.
could you suggest what needs to be added to get name and guest of vm.
virtualmachine.guest returns an instance of type VcGuestInfo. It is a complex type, not as simple as plain string or number, so that's the reason it is formatted like shown on the screenshot.
If you lookup VcGuestInfo in vRO API Explorer, you can see its available properties. So, in your System.log() statements instead of virtualmachine.guest you can use virtualmachine.guest.<property> to log some particular property, for example, virtualmachine.guest.guestFullName.
This has worked thanks for your response.
but "guestFullName" comes under vcGuestInfo object so in order to have dot notation should it not be ???
" vmguest :" + virtualmachine.GuestInfo.guestFullName); though it did not work .
No, the property of the virtual machine class that returns guest info is named guest, so the proper expression is virtualmachine.guest.guestFullName
thnaks.