Hi,
How can I get the datacenter location name of an esx host with vRO?
Thanks!
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.
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 }
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.