Enthusiast
Enthusiast

How to list the Distributed switches of a vC Cluster?

Jump to solution

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

0 Kudos
1 Solution

Accepted Solutions
VMware Employee
VMware Employee

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

0 Kudos
1 Reply
VMware Employee
VMware Employee

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

0 Kudos