VMware {code} Community
minghuig
Contributor
Contributor

getting VM hostname

VirtualMachine->summary->guest->hostName seems to be giving me the DNS name of the VM, not the hostname... Is there a way I can get the actual hostname? Thanks!

0 Kudos
2 Replies
njain
Expert
Expert

Are you looking for the host name that is running this VM? This information can be fetched from VirtualMachine->runtime->host property. This will give you a managed object reference to the host. You can then retrieve the "name" property from the MOR to get the name of the host.

Hope this information is helpful.

0 Kudos
mikefoley
VMware Employee
VMware Employee

Here ya go... From my CGI script at: http://communities.vmware.com/thread/202882

  1. Create the managed object reference from the two variables we split up earlier.

my $my_moref =

ManagedObjectReference->new( type => $VMobjtype, value => $VMname );

  1. Get the specific VM view

my $vm = Vim::get_view( mo_ref => $my_moref );

#

  1. Get the DNS Hostname of the VM.

my $DNShostname = $vm->summary->guest->hostName;

mike

0 Kudos