VMware Cloud Community
orian
Hot Shot
Hot Shot
Jump to solution

Get datacenter of esxhost

Hi,

How can I get the datacenter location name of an esx host with vRO?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Here is some sample scripting code (the input parameter is the variable host of type VC:HostSystem)

var hostparent = host.parent; 

while (hostparent != null && !(hostparent instanceof VcDatacenter)) { 

    hostparent = hostparent.parent; 

if (hostparent == null) { 

    System.log("Parent datacenter not found."); 

} else { 

    System.log("Parent datacenter name: " + hostparent.name); 

}

The idea is to iterate up inventory hierarchy, starting from the esx host, until you find the parent datacenter object.

View solution in original post

0 Kudos
2 Replies
hawks76
Enthusiast
Enthusiast
Jump to solution

Probably easiest way to do it is run a powercli script through powershell host and return it there.

Something like this:

Get-VMHost vmhostname | % {$_.Parent.ParentFolder.Parent.Name }

0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Here is some sample scripting code (the input parameter is the variable host of type VC:HostSystem)

var hostparent = host.parent; 

while (hostparent != null && !(hostparent instanceof VcDatacenter)) { 

    hostparent = hostparent.parent; 

if (hostparent == null) { 

    System.log("Parent datacenter not found."); 

} else { 

    System.log("Parent datacenter name: " + hostparent.name); 

}

The idea is to iterate up inventory hierarchy, starting from the esx host, until you find the parent datacenter object.

0 Kudos