Highlighted
Enthusiast
Enthusiast

Portgroup/VLAN Tag Report

Jump to solution

Hey all,

I am looking for a report to show all portgroups and what VLAN Tags they are using.  Just want to use this for quick comparison and verification that everything is working.  We currently use for vSSs and vDSs, so it would be great if for the vSSs to show the vHost that they reside on.  Let me know if this is an achievable goal or just a dream.


Thanks all,Andy

0 Kudos
1 Solution

Accepted Solutions
Highlighted
VMware Employee
VMware Employee

You can try the below script for the port groups report :

Connect-VIServer -Server 'server' -User 'user' -Password 'passwd'

$Report = @()

foreach ($spg in (Get-VirtualPortGroup -Standard))

       {

         $row = "" | Select Name,VLanId

         $row.Name = $spg.Name

         $row.VLanId = $spg.VLanId

         $Report += $row

      }

foreach ($dpg in Get-VDPortgroup)

      {

        $row = "" | Select Name,VLanId

        $row.Name = $dpg.Name

        if($dpg.Extensiondata.Config.DefaultPortCOnfig.Vlan.VlanId -match '\d')

         {

           $row.VLanId = $dpg.Extensiondata.Config.DefaultPortCOnfig.Vlan.VlanId

         }

        else

         {

            $start = $dpg.Extensiondata.Config.DefaultPortCOnfig.Vlan.VlanId.Start

            $end = $dpg.Extensiondata.Config.DefaultPortCOnfig.Vlan.VlanId.End

            $row.VLanId = "$start" + ' - ' + "$end"

          }

        $Report += $row

        }


$Report | Export-Csv "test.csv"

The ask related to vSSs hostname is not clear to me.

If you just need the vSS to hostname mapping then you can use the below :

Get-VirtualSwitch -Standard | select Name, @{N="HostName";E={$_.VMHost.Name}}

View solution in original post

0 Kudos
4 Replies
Highlighted
User Moderator
User Moderator

Have a look at 2.  Re: List Portgroups with Private VLANS

I think it shows all the info you are looking for.


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

0 Kudos
Highlighted
VMware Employee
VMware Employee

You can try the below script for the port groups report :

Connect-VIServer -Server 'server' -User 'user' -Password 'passwd'

$Report = @()

foreach ($spg in (Get-VirtualPortGroup -Standard))

       {

         $row = "" | Select Name,VLanId

         $row.Name = $spg.Name

         $row.VLanId = $spg.VLanId

         $Report += $row

      }

foreach ($dpg in Get-VDPortgroup)

      {

        $row = "" | Select Name,VLanId

        $row.Name = $dpg.Name

        if($dpg.Extensiondata.Config.DefaultPortCOnfig.Vlan.VlanId -match '\d')

         {

           $row.VLanId = $dpg.Extensiondata.Config.DefaultPortCOnfig.Vlan.VlanId

         }

        else

         {

            $start = $dpg.Extensiondata.Config.DefaultPortCOnfig.Vlan.VlanId.Start

            $end = $dpg.Extensiondata.Config.DefaultPortCOnfig.Vlan.VlanId.End

            $row.VLanId = "$start" + ' - ' + "$end"

          }

        $Report += $row

        }


$Report | Export-Csv "test.csv"

The ask related to vSSs hostname is not clear to me.

If you just need the vSS to hostname mapping then you can use the below :

Get-VirtualSwitch -Standard | select Name, @{N="HostName";E={$_.VMHost.Name}}

View solution in original post

0 Kudos
Highlighted
Enthusiast
Enthusiast

Sorry for the leaving this post high and dry, but I finally got back to this and tested.  This is very close to what I am looking for is just like you have except, when it comes to the VSS portgroups your script has the VSS portgroup in column 1 and the VLAN tag in column 2, but I also need the vHost that the VSS is on so I can hunt down if I have a VLAN tag incorrectly configured.  The rest of what you have is perfect.

Thank you for any help,
Andy

0 Kudos
Highlighted
User Moderator
User Moderator

The thread I linked to earlier does contain the ESXi node name


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

0 Kudos