Created
February 10, 2017 21:23
-
-
Save sdorsett/904a7e91a04c8e7a7f8590366ef9ed1a to your computer and use it in GitHub Desktop.
rbvmomi - find all virtual machines with 'desktop' in the name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rbvmomi' | |
hostname = '192.168.1.200'; | |
username = 'user1@vsphere.local'; | |
password = 'P@ssword123'; | |
vim = RbVmomi::VIM.connect host: hostname, user: username, password: password, insecure: true; | |
rootFolder = vim.serviceInstance.content.rootFolder | |
viewManager = vim.serviceInstance.content.viewManager | |
viewManager.CreateContainerView( | |
recursive: true, container: rootFolder, type: ['Datacenter'] | |
).view.each{|dc| | |
viewManager.CreateContainerView( | |
recursive: true, container: dc, type: ['ComputeResource'] | |
).view.each{|cluster| | |
viewManager.CreateContainerView( | |
recursive: true, container: cluster, type: ['VirtualMachine'] | |
).view. | |
select{|vm| | |
vm.name =~ /desktop/ | |
}. | |
each{|vm| | |
puts "in datacenter #{dc.name}, cluster #{cluster.name}: vm #{vm.name}" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment