Automation

 View Only
  • 1.  List Portgroups with Private VLANS

    Posted Feb 10, 2017 02:17 AM

    Hi I was wondering if someone can help with listing all portgroups in a cluster or datacenter that are configured with Private VLAN so I want to ignore PG's with standard or no vlans?



  • 2.  RE: List Portgroups with Private VLANS

    Posted Feb 10, 2017 03:27 AM

    Ok I found the syntax to list all portgroups with Private VLANS but I would like to list VMs connected to those VLANS ?

    Get-VDSwitch | Get-VDSwitchPrivateVlan



  • 3.  RE: List Portgroups with Private VLANS
    Best Answer

    Posted Feb 10, 2017 06:33 AM

    This is probably too much, but includes the connected VMs.

    Get-VirtualPortGroup |

    Select Name,

        @{N='Host';E={

            if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){

                [string]::Join(',',(Get-View -Id $_.ExtensionData.Host -Property Name | %{$_.Name}))

            }

            else{

                Get-View -Id $_.VMHostId | Select -ExpandProperty Name

            }}},

        @{N='SwitchType';E={

            if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){

                'VDS'

            }

            else{'VSS'}}},

        @{N='VLANType';E={

            if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){

                switch($_.ExtensionData.Config.DefaultPortConfig.Vlan.GetType().Name){

                'VmwareDistributedVirtualSwitchPvlanSpec' {'PvLAN'}

                'mwareDistributedVirtualSwitchVlanIdSpec' {'VLAN'}

                'VmwareDistributedVirtualSwitchTrunkVlanSpec' {'VLAN Trunking'}

                Default {'None'}

                }

            }

            else{           

                $_.ExtensionData.GetType().Name

            }}},

        @{N='VlanId';E={

            if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){

                if($_.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchPvlanSpec]){

                    $_.ExtensionData.Config.DefaultPortConfig.Vlan.PvlanId

                }

                elseif($_.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchVlanSpec]){

                    if($_.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId -is [VMware.Vim.NumericRange[]]){

                        [string]::Join(',',($_.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId | %{"$($_.Start)-$($_.End)"}))

                    }

                    else{

                        $_.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId

                    }

                }

            }

            else{$_.VlanId}}},

        @{N='Available ports';E={

            if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){

                $_.numPorts - $_.ExtensionData.Vm.Count

            }

            else{'na'}}},

        @{N='Total ports';E={

            if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){

                $_.NumPorts

            }

            else{'na'}}},

        @{N='VM';E={(Get-View -Id $_.ExtensionData.VM -Property Name | %{$_.Name}) -join '|'}}



  • 4.  RE: List Portgroups with Private VLANS

    Posted Feb 16, 2017 11:57 PM

    Hi Luc,

    This works well, what would i remove to filter out hosts as that info is not needed?

    Cheers



  • 5.  RE: List Portgroups with Private VLANS

    Posted Feb 17, 2017 12:39 AM

    Hi Luc,

    I was actually able to export to CSV the just delete the host column so its ok, the other this is it didn't actually filter out only PvLAN and listed or VDS portgroups so i added this to the end which seems to work well

    ?{$_.VLANType -like "PvLAN"} | Export-Csv -NoTypeInformation -UseCulture  c:\scripts\pvlan-vm.csv

    The only think I wold like is to list VM's a little better but it will certainly do the job, thank you again for your help, much appreciated.

    Cheers



  • 6.  RE: List Portgroups with Private VLANS

    Posted Feb 17, 2017 05:44 AM

    How owuld you like to see the connected VMs?

    I did a -join to get it all in one value.



  • 7.  RE: List Portgroups with Private VLANS

    Posted Feb 17, 2017 11:34 AM

    Hi Luc,

    The VM list is fine, probably not many option here, we may have like 10 VMs on one PG and they kind of stitched together and a bit hard to read, possibly some more space between the VM names. If the -join was removed how would it format?

    Cheers



  • 8.  RE: List Portgroups with Private VLANS

    Posted Feb 17, 2017 11:52 AM

    If you leave out the -join, the property will be an array, and not behave well when you do an Export-Csv for example.

    You can add space on the -join, for example: -join ' | '



  • 9.  RE: List Portgroups with Private VLANS

    Posted Feb 17, 2017 11:58 AM

    Hi Luc,

    Thanks I'll give that a try.

    Cheers