Hot Shot
Hot Shot

getting virtual machines names_vRO

I am trying to get virtual mchinesnames using vRO.

created following workflow.

pastedImage_0.png

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.

0 Kudos
8 Replies
VMware Employee
VMware Employee

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)

0 Kudos
Hot Shot
Hot Shot

Thanks it worked however during validation it did not throw error even there was semicoloneafter for each bracket.

0 Kudos
VMware Employee
VMware Employee

Yes, because it is a valid Javascript code - a loop with no body, and a single scoped statement after it.

0 Kudos
Hot Shot
Hot Shot

Thnaks.i also thought of utilizing  another property of VcVirtualMachine object .one of them is guest .

pastedImage_0.png

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.

pastedImage_3.png

could you suggest what needs to be added to get name and guest of vm.

0 Kudos
VMware Employee
VMware Employee

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.

0 Kudos
Hot Shot
Hot Shot

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 .       

pastedImage_0.png

0 Kudos
VMware Employee
VMware Employee

No, the property of the virtual machine class that returns guest info is named guest, so the proper expression is virtualmachine.guest.guestFullName

0 Kudos
Hot Shot
Hot Shot

thnaks.

0 Kudos