That's an old one I wrote :smileywink:
In that script, the generic child_view call is just a cheap, fast way to get the name and object type. I cheat a bit and use a common property 'name' in the Vim:get_view() call to do a the printing on both folders and VMs.
But if you wanted the VM power state, you would have to get the power state property as well. Not the most efficient way of getting the data, but should work without major script rework (should work not tested, but idea is sound) --
foreach $mo ( @{$entity_view->childEntity} )
{
$child_view = Vim::get_view(
mo_ref => $mo, properties => ['name']
);
if ( $child_view->isa("VirtualMachine") )
{
$vm_view = Vim::get_view(mo_ref => $mo, properties => [ 'name', 'runtime.powerstate' ]);
print " " x $index . "Virtual Machine: " . $child_view->name . "(PowerState=)" . $vm_view->{'runtime.powerstate'}->val . "\n" ;
}
if ( $child_view->isa("Folder") )
{
print " " x $index . "Folder: " . $child_view->name . "\n";
$child_view = Vim::get_view(
mo_ref => $mo, properties => ['name', 'childEntity']
);
TraverseFolder($mo, $index);
}
}
You could also check the MOREF type and have an if around the call to get the $child_view (if VirtualMachine, then call get_view with the runtime.powerstate, if not, just call 'name').