Script

----------------------------------------------------------------------------------

Add-PSSnapin vmWARE.VimAutomation.Core

$vc="devvc55"
connect-viserver $vc
$date = Get-Date -Format 'yyyyMMdd'


 $VLANinfo = foreach ($cluster in get-cluster) 
       {
            foreach ($esx in (Get-VMHost -Location $cluster)) 
       {
            foreach ($pg in (Get-VirtualPortGroup -VMHost $esx))
 
       {
         Select-Object -InputObject $pg -Property @{N="Cluster"; E={$cluster.Name}},
                                    @{N="VMhost";  E={$esx.Name}},
                                    @{N="VirtualSwitchName"; E={$pg.VirtualSwitchName}},
                                    @{N="portgroup"; E={$pg.Name}},
                                    @{N="VLAN";      E={$pg.VlanID}}
                }
                }
                }

$VLANinfo | Export-Csv "C:\PS\report\$($vc)_allPortGroup_$date.csv"