VMware Cloud Community
jaydo123
Contributor
Contributor

why is this script not getting the VLAN ID?

Hi I need to gather the VLAN information against my environment to check to see if VLAN's have been configured

$report = @()

foreach($esx in Get-VMHost){

    $vms = Get-VM -Location $esx

    foreach($pg in (Get-VirtualPortGroup -VMHost $esx)){

        $vms | where {$_.Guest.Nics | where {$_.NetworkName -eq $pg.Name}} | foreach {

            $Report += New-Object PSObject -Property @{

                "Host"=$esx.Name

                "VM"=$_.Name

                "VLAN ID"=$pg.VlanId

                "Port Group"=$pg.Name

                "IP"=[string]::Join(',',($_.Guest.Nics | where {$_.NetworkName -eq $pg.Name} | %{$_.IPAddress | %{$_}}))

            }

        }

    }

}

$report | Export-Csv "C:\testVLAN-report.csv" -NoTypeInformation -UseCulture

this gathers most of the information but isn't pull back the VLAN ID?  anybody know why?

0 Kudos
3 Replies
LucD
Leadership
Leadership

Are the ones that are missing by any chance portgroups on dvSwitches ?

Seems to be ok for portgroups on regular vSwitches.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jaydo123
Contributor
Contributor

Yes Luc

you are correct it work on standard vSwitch but not on dvSwitches

I know the is a new cmdlet get-VDPortGroup which gathers the dvSwtich Vlan Configuration but i would like to be able to have both in the report

0 Kudos
LucD
Leadership
Leadership

0 Kudos