VMware Cloud Community
lurims
Enthusiast
Enthusiast
Jump to solution

How to list the Distributed switches of a vC Cluster?

How to list the Distributed switches of a vCenter Cluster?  I did not see a property in VC:ClusterComputeResource.

Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Check the following code (the input variable is cluster😞

for each (var host in cluster.host) {

  for each (var net in host.network) {

    if (net.config == null) continue;

    var dvs = net.config.distributedVirtualSwitch;

    System.log(dvs.name + " (id: " + dvs.id + ")");

  }

}

The above code will print distributed virtual switches' names and IDs.

Note that it may, and likely will, print a lot of duplicate entries, as one distributed virtual switch can be associated with multiple hosts. So you may need to add some extra code to filter out the duplicate entries from the output of the above code.

View solution in original post

Reply
0 Kudos
1 Reply
iiliev
VMware Employee
VMware Employee
Jump to solution

Check the following code (the input variable is cluster😞

for each (var host in cluster.host) {

  for each (var net in host.network) {

    if (net.config == null) continue;

    var dvs = net.config.distributedVirtualSwitch;

    System.log(dvs.name + " (id: " + dvs.id + ")");

  }

}

The above code will print distributed virtual switches' names and IDs.

Note that it may, and likely will, print a lot of duplicate entries, as one distributed virtual switch can be associated with multiple hosts. So you may need to add some extra code to filter out the duplicate entries from the output of the above code.

Reply
0 Kudos