Almost there - I had exactly the same issue - your loop is skipping subfolders. To get all of the VMs, you need to recurse down thru them. Try something like this (ripped from my own working code):
def vms(folder) # recursively go thru a folder, dumping vm info
folder.childEntity.each do |x|
name, junk = x.to_s.split('(')
case name
when "Folder"
vms(x)
when "VirtualMachine"
puts x.name
else
puts "# Unrecognized Entity " + x.to_s
end
end
end
That's obviously starting at the top-level folder in a datacenter, not the DC itself. I don't actually have multiple datacenters in my setup - but it doesn't appear that find_datacenter supports something like .each - so you'd probably want to wrap that up in a loop like:
dcs = ['firstdc', 'seconddc', 'thirddc']
dcs.each do |dc|
vms(vim1.serviceInstance.find_datacenter(dc).vmFolder)
end