VMware

Get-VLANHealthCheck : PowerCLI cmdlet which pulls the results from vSphere’s Distributed Switch health check.

Hi everybody,
Hopefully this is helpful to some of you.

I’ve found if you are needing to use the [vSphere Distributed Switch health check](https://kb.vmware.com/s/article/2032878), you have to wrestle with the UI if you have lots of hosts and/or lots of VLANs.

There’s no scrolling to the right and there is no exporting, that I can find, of the information.

So I took a swing at piecing together a PowerCLI cmdlet which can pull that information.

https://github.com/mrbassplayer/Get-VLANHealthCheck

*Sample Output:*

Get-VLANHealthCheck -ClusterName_str Cluster1 -vdSwitchName_str vDS-SiteA-M1
Host PNic Speed MAC DeviceID PortID vdSwitch UplinkPortKey UnTrunkedVLAN TrunkedVLAN
—- —- —– — ——– —— ——– ————- ————- ———–
myHost2.contoso.com vmnic4 10000 00:00:00:00:00:00 sw1.contoso.com Eth1/9 vDS-SiteA-M1 96 62,63,64 58,59,60,61,226,227,456,942,949
myHost2.contoso.com vmnic5 10000 00:00:00:00:00:00 sw2.contoso.com Eth1/10 vDS-SiteA-M1 97 58,59,60,61,62,63,64,226,227,456,942,949
myHost2.contoso.com vmnic6 10000 00:00:00:00:00:00 sw1.contoso.com Eth1/10 vDS-SiteA-M1 98 62,63,64 58,59,60,61,226,227,456,942,949
myHost2.contoso.com vmnic7 10000 00:00:00:00:00:00 sw2.contoso.com Eth1/9 vDS-SiteA-M1 99 58,59,60,61,62,63,64,226-227,456,942,949
myHost1.contoso.com vmnic4 10000 00:00:00:00:00:00 sw1.contoso.com Eth1/8 vDS-SiteA-M1 103 62,63,64 58,59,60,61,226,227,456,942,949
myHost1.contoso.com vmnic5 10000 00:00:00:00:00:00 sw2.contoso.com Eth1/8 vDS-SiteA-M1 104 58,59,60,61,62,63,64,226,227,456,942,949
myHost1.contoso.com vmnic6 10000 00:00:00:00:00:00 sw2.contoso.com Eth1/7 vDS-SiteA-M1 105 58,59,60,61,62,63,64,226,227,456,942,949
myHost1.contoso.com vmnic7 10000 00:00:00:00:00:00 sw1.contoso.com Eth1/7 vDS-SiteA-M1 106 62,63,64 58,59,60,61,226,227,456,942,949
myHost3.contoso.com vmnic4 10000 00:00:00:00:00:00 sw2.contoso.com Eth1/12 vDS-SiteA-M1 366 58,59,60,61,62,63,64,226,227,456,942,949
myHost3.contoso.com vmnic5 10000 00:00:00:00:00:00 sw2.contoso.com Eth1/11 vDS-SiteA-M1 367 58,59,60,61,62,63,64,226,227,456,942,949
myHost3.contoso.com vmnic6 10000 00:00:00:00:00:00 sw1.contoso.com Eth1/12 vDS-SiteA-M1 368 62,63,64 58,59,60,61,226,227,456,942,949
myHost3.contoso.com vmnic7 10000 00:00:00:00:00:00 sw1.contoso.com Eth1/11 vDS-SiteA-M1 369 62,63,64 58,59,60,61,226,227,456,942,949
Gets all hosts in ‘Cluster1’ and shows results for all vmnics connected to ‘vDS-SiteA-M1’ and shows the results in “Comma Only” format.

Get-VLANHealthCheck -ClusterName_str Cluster1 -vdSwitchName_str vDS-SiteA-M1 -CommaDash
Host PNic Speed MAC DeviceID PortID vdSwitch UplinkPortKey UnTrunkedVLAN TrunkedVLAN
—- —- —– — ——– —— ——– ————- ————- ———–
myHost2.contoso.com vmnic4 10000 00:00:00:00:00:00 sw1.contoso.com Eth1/9 vDS-SiteA-M1 96 62-64 58-61,226,227,456,942,949
myHost2.contoso.com vmnic5 10000 00:00:00:00:00:00 sw2.contoso.com Eth1/10 vDS-SiteA-M1 97 58-64,226,227,456,942,949
myHost2.contoso.com vmnic6 10000 00:00:00:00:00:00 sw1.contoso.com Eth1/10 vDS-SiteA-M1 98 62-64 58-61,226,227,456,942,949
myHost2.contoso.com vmnic7 10000 00:00:00:00:00:00 sw2.contoso.com Eth1/9 vDS-SiteA-M1 99 58-64,226,227,456,942,949
myHost1.contoso.com vmnic4 10000 00:00:00:00:00:00 sw1.contoso.com Eth1/8 vDS-SiteA-M1 103 62-64 58-61,226,227,456,942,949
myHost1.contoso.com vmnic5 10000 00:00:00:00:00:00 sw2.contoso.com Eth1/8 vDS-SiteA-M1 104 58-64,226,227,456,942,949
myHost1.contoso.com vmnic6 10000 00:00:00:00:00:00 sw2.contoso.com Eth1/7 vDS-SiteA-M1 105 58-64,226,227,456,942,949
myHost1.contoso.com vmnic7 10000 00:00:00:00:00:00 sw1.contoso.com Eth1/7 vDS-SiteA-M1 106 62-64 58-61,226,227,456,942,949
myHost3.contoso.com vmnic4 10000 00:00:00:00:00:00 sw2.contoso.com Eth1/12 vDS-SiteA-M1 366 58-64,226,227,456,942,949
myHost3.contoso.com vmnic5 10000 00:00:00:00:00:00 sw2.contoso.com Eth1/11 vDS-SiteA-M1 367 58-64,226,227,456,942,949
myHost3.contoso.com vmnic6 10000 00:00:00:00:00:00 sw1.contoso.com Eth1/12 vDS-SiteA-M1 368 62-64 58-61,226,227,456,942,949
myHost3.contoso.com vmnic7 10000 00:00:00:00:00:00 sw1.contoso.com Eth1/11 vDS-SiteA-M1 369 62-64 58-61,226,227,456,942,949
Gets all hosts in ‘Cluster1’ and shows results for all vmnics connected to ‘vDS-SiteA-M1’ and shows the results in “Comma Dash” format.

Mad props to [Matt Boren](https://twitter.com/mtboren?lang=en) for helping me speed up the turnaround time of the script.

In my environment, which has 60+ hosts, each with four vmnics, and over 200 VLANs, the script took about 57 seconds to process.

Matt helped me get this down to 17 seconds.

Also, thanks to [LucD](https://www.lucd.info/). The things I’ve learned from him over the years have definitely made their way into my code. This solution of his, in particular, solved parsing the Trunked and UnTrunked VLANs.

FYI: Would’ve posted this to /r/powercli but it is not allowing posting right now? When did that happen?

Again, I hope some of you find this useful.


View Reddit by groovel76View Source

Related Articles

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Close