VMware Cloud Community
lurims
Enthusiast
Enthusiast

Getting all ESXi host systems of vCenter using Server.findAllForType

Trying to make a query that build all ESXi hosts of a vCenter using Server.findAllForType.  Tried this code but did not work.  Could anyone help?

var vc = myvCenter.abc.com;

var allESXihosts = Server.findAllForType("VC:HostSystem", "vimHost.id eq '" + vc + "'");

System.log(allESXihosts.length);

for each(var host in allESXihosts){

     System.log(host.name + ',' + host.vimHost.id);

}

1 Reply
lurims
Enthusiast
Enthusiast

This did the magic, and credits goes to this discusion

var query = "xpath:sdkConnection/id[.='" + vC + "']";