Automation

 View Only
  • 1.  Script to get VLANs IDs observed by ESXi

    Posted Oct 28, 2019 06:16 PM

    Hello Everyone,

    Anyone could help me with a PowerCli script to get VLANs IDs observed by ESXi server? I want o run this script in a specific cluster and export it to excel csv file.

    Thanks.



  • 2.  RE: Script to get VLANs IDs observed by ESXi

    Posted Oct 28, 2019 06:25 PM

    Do you mean like this?

    $clusterName = 'cluster'

    Get-Cluster -Name $clusterName -PipelineVariable cluster |

    Get-VMHost -PipelineVariable esx |

    Get-VirtualPortGroup |

    select @{N='Cluster';E={$cluster.Name}},@{N='VMHost';E={$esx.Name}},VirtualSwitch,Name,VlanId |

    Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture



  • 3.  RE: Script to get VLANs IDs observed by ESXi

    Posted Oct 28, 2019 06:55 PM

    Hi LucD, thanks for the quick reply.

    I want to get VLANs IDs observed by ESXi, it is the CDP information, VLANs trucked.

    Thanks.



  • 4.  RE: Script to get VLANs IDs observed by ESXi

    Posted Oct 28, 2019 07:23 PM

    Like this?

    $clusterName = 'cluster'

    Get-Cluster -Name $clusterName -PipelineVariable cluster |

    Get-VMHost -PipelineVariable esx |

    ForEach-Object -Process {

       $netSys = Get-View -Id $esx.ExtensionData.ConfigManager.NetworkSystem

       Get-VMHostNetworkAdapter -VMHost $esx -Physical -Name vmnic* |

       Select @{N='Cluster';E={$cluster.Name}},

        @{N='VMHost';E={$esx.Name}},

        @{N='Nic';E={$_.Name}},

        @{N='VlanIds';E={($netSys.QueryNetworkHint($_.Name)).Subnet.VlanId -join '|'}}

    } | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture



  • 5.  RE: Script to get VLANs IDs observed by ESXi

    Posted 22 days ago

    Hi LucD, this is very good :) How can I get the portgroup name by vmnic in the same statement?




  • 6.  RE: Script to get VLANs IDs observed by ESXi

    Posted 18 days ago

    LLDP/CDP information via the vnic is not reliable. LLDP/CDP only shows what is observed with a passive sampling of traffic. So, the ESXi hosts will only report what it MIGHT see, not what is actually trunked. If the ESXi hosts is in a busy cluster and all trunked VLANs are active, it should have more complete VLAN list from LLDP/CDP, but it should not be trusted as authoritative.

    Here is a good thread on it.
    https://community.broadcom.com/vmware-cloud-foundation/discussion/vlan-not-showing-in-esxi-cdp-output