Automation

 View Only
Expand all | Collapse all

Extract All vSS & VDS details for all vCenters

  • 1.  Extract All vSS & VDS details for all vCenters

    Posted Nov 15, 2020 04:52 PM

    In order to remedy a large network configuration issue, I need to collect vSS & VDS details across all vCenters.

    I'm not sure if we can collect both Standard switch and distributed switch in one shot and the output should contain the below information:

    • HostName
    • Type : Standard or Distributed
    • vSwitch MTU
    • version
    • Name
    • Uplink /ConnectedAdapter
    • PortGroup
    • VLAN ID
    • Active adapters
    • Standby Adapters
    • Unused Adapters
    • Security Promiscuous/MacChanges/ForgedTransmits

     

     

     

     



  • 2.  RE: Extract All vSS & VDS details for all vCenters

    Posted Nov 15, 2020 05:52 PM

    You can collect all that in 1 report, but the code might become quite complex.

    What do you mean by 'Version' in case of a VSS?
    What do you mean by 'Unused Adapters'?

    Do you intend to list all pNIC that are not used in the Switch or Portgroup?

    On VDS the concept of active/standby pNIC does not really exist.
    The teaming is done through the Uplinks.

    And, more importantly, what do you already have?
    I'm pretty sure a lot of the information you are after is already present in this community.



  • 3.  RE: Extract All vSS & VDS details for all vCenters

    Posted Nov 15, 2020 06:08 PM

    yep I confirm that the code might be complex 

    What do you mean by 'Version' in case of a VSS? my bad as the version is related to vDS, 
    What do you mean by 'Unused Adapters'? unfortunately the current configuration has some unused Uplink

     

    Do you intend to list all pNIC that are not used in the Switch or Portgroup? it should be the case

     

    I have the 2 below scripts, but not able to mix them in order to collect what I need

     

    Get-VMHostNetworkAdapter -vmkernel |
    % { $vnet=$_ ; get-vdportgroup -vmhostnetworkadapter $vnet |
    %{"$($vnet.vmhost.parent)`t$($vnet.vmhost)`t
    $($vnet.name)`t$($vnet.ip)`t$($vnet.subnetmask)`t
    $($_.name)`t$($_.vdswitch)`t$($_.vlanconfiguration)" |
    out-file .\temp\output.txt -append } }

    Get-VirtualPortgroup -standard |
    % { $pg=$_ ; get-vmhostnetworkadapter -portgroup $pg |
    % { "$($_.vmhost.parent)`t$($_.vmhost)`t$($_.name)`t
    $($_.ip)`t$($_.subnetmask)`t$($pg.name)`t
    $($pg.virtualswitch.name)`t$($pg.vlanid)" |
     out-file .\temp\output.txt -append }}

    Any comments or recommendation are always welcome

     



  • 4.  RE: Extract All vSS & VDS details for all vCenters

    Posted Nov 16, 2020 01:19 PM

    Try something like this

    Get-VMHost -PipelineVariable esx |
    ForEach-Object -Process {
        Get-VirtualSwitch -VMHost $esx -PipelineVariable sw |
        ForEach-Object -Process {
            Get-VirtualPortGroup -VirtualSwitch $sw -PipelineVariable pg |
            ForEach-Object -Process {
                New-Object -TypeName PSObject -Property ([ordered]@{
                    VMHost = $esx.name
                    Switch = $sw.Name
                    Type = $sw.GetType().Name -replace 'Impl',''
                    Mtu = $sw.mtu
                    Portgroup = $pg.Name
                    VlanId = &{
                        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}}
                    Uplink = &{
                        if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
                            $vds.ExtensionData.Config.UplinkPortPolicy.UplinkPortName -join ','
                        }
                        else{
                           'na'
                        }                    
                    }
                    ConnectedAdapter = &{
                        if($pg -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
                            $vds = $esx.ExtensionData.Config.Network.ProxySwitch | where{$_.DvsUuid -eq $sw.ExtensionData.Uuid}
                            ($vds.UplinkPort | ForEach-Object -Process {
                                $uplink = $_
                                $pnic = $vds.Spec.Backing.PnicSpec | where{$uplink.Key -eq $_.UplinkPortKey}
                                if($pnic){
                                    "$($uplink.Value):$($pnic.PnicDevice)"
                                }
                                else{"$($uplink.Value):-"}
                            }) -join ','
                        }
                        else{
                           $sw.Nic -join ','
                        }
                    }
                    ActiveNic = &{
                        if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
                            'na'
                        }
                        else{
                            if($pg.ExtensionData.Spec.Policy.NicTeaming.NicOrder -ne $null){
                               $pg.ExtensionData.Spec.Policy.NicTeaming.NicOrder.ActiveNic -join ','
                            }
                            else{
                                $sw.ExtensionData.Spec.Policy.NicTeaming.NicOrder.ActiveNic -join ','
                            }
                        }                    
                    }
                    StandByNic = &{
                        if($pg -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
                            'na'
                        }
                        else{
                            if($pg.ExtensionData.Spec.Policy.NicTeaming.NicOrder -ne $null){
                               $pg.ExtensionData.Spec.Policy.NicTeaming.NicOrder.StandByNic -join ','
                            }
                            else{
                                $sw.ExtensionData.Spec.Policy.NicTeaming.NicOrder.StandByNic -join ','
                            }
                        }                    
                    }
                    SwPromicious = &{
                        if($pg -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
                            $sw.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.AllowPromiscuous.Value
                        }
                        else{
                            $sw.ExtensionData.Spec.Policy.Security.AllowPromiscuous
                        }
                    }
                    SwMacChanges = &{
                        if($pg -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
                            $sw.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.MacChanges.Value
                        }
                        else{
                            $sw.ExtensionData.Spec.Policy.Security.MacChanges
                        }
                    }
                    SwForgedTransmits = &{
                        if($pg -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
                            $sw.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.ForgedTransmits.Value
                        }
                        else{
                            $sw.ExtensionData.Spec.Policy.Security.ForgedTransmits
                        }
                    }
                    PgPromicious = &{
                        if($pg -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
                            $pg.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.AllowPromiscuous.Value
                        }
                        else{
                            $pg.ExtensionData.Spec.Policy.Security.AllowPromiscuous
                        }
                    }
                    PgMacChanges = &{
                        if($pg -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
                            $pg.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.MacChanges.Value
                        }
                        else{
                            $pg.ExtensionData.Spec.Policy.Security.MacChanges
                        }
                    }
                    PgForgedTransmits = &{
                        if($pg -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
                            $pg.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.ForgedTransmits.Value
                        }
                        else{
                            $pg.ExtensionData.Spec.Policy.Security.ForgedTransmits
                        }
                    }
                })
            }
        }
    }

     



  • 5.  RE: Extract All vSS & VDS details for all vCenters

    Posted Nov 16, 2020 05:07 PM
    I added
    $results = @() at the begin of the script
    $results | export-csv -Path .\Output.csv -NoTypeInformation at the end
    the file is created but is empty,
    i think i'm wrong


  • 6.  RE: Extract All vSS & VDS details for all vCenters

    Posted Nov 16, 2020 05:12 PM

    The script doesn't use a $results variable.
    All objects are in the pipeline, you can just pipe the object to your Export-Csv cmdlet.



  • 7.  RE: Extract All vSS & VDS details for all vCenters

    Posted Apr 15, 2022 04:20 PM

     

    I find this script and it provide good details, unfortunately I'm not able to generate a CSV/Excel is that possible?

    for this script can we add information like physical switch Name and switch Ports?

     



  • 8.  RE: Extract All vSS & VDS details for all vCenters

    Posted Apr 15, 2022 04:35 PM

    See my previous answer, you should be able to add (pipe) at the end to an EXport-Csv cmdlet.

    Physical info is only present when CDP, or similar, is actived.



  • 9.  RE: Extract All vSS & VDS details for all vCenters

    Posted Apr 15, 2022 04:56 PM

    Thank you very much I'm able to export the report

    the CDP is activated on the switch so it's possible to add the information?



  • 10.  RE: Extract All vSS & VDS details for all vCenters

    Posted Apr 15, 2022 05:10 PM

    Extracting the CDP info is not a problem, but I'm not sure how to present that in the output.

    The following, CDS only, would perhaps be a better solution.
    See Re: Collect vDS Portgroup, VMNIC and CDP informati... - VMware Technology Network VMTN



  • 11.  RE: Extract All vSS & VDS details for all vCenters

    Posted Apr 19, 2022 12:35 PM

    Thanks 

     

    to the previous script can we add at least IP adress?



  • 12.  RE: Extract All vSS & VDS details for all vCenters

    Posted Apr 21, 2023 05:55 AM

    Hello 

    II'm using the above script to collect details for network, unfortunately the active standby output show always "na" despite the Configuration is active/standby, I do have any idea what could be the issue? 

     



  • 13.  RE: Extract All vSS & VDS details for all vCenters

    Posted Apr 21, 2023 06:42 AM

    It is rather simple, I didn't implement that in the code at the time.



  • 14.  RE: Extract All vSS & VDS details for all vCenters

    Posted Apr 21, 2023 08:32 AM

     

    Thank you I will try to add that include it 



  • 15.  RE: Extract All vSS & VDS details for all vCenters

    Posted May 09, 2023 03:04 PM

     

    I didn't find the way to show the information for ActiveNic/StandByNic

    would you please assist on this?



  • 16.  RE: Extract All vSS & VDS details for all vCenters

    Posted Nov 07, 2023 06:37 AM

    Hello LucD,

    I'm somehow still getting the vlan ID colon empty. Any hint?

     

    Thank you



  • 17.  RE: Extract All vSS & VDS details for all vCenters

    Posted Nov 07, 2023 07:34 AM

    Are you using VSS or VDS, or a mix?
    ANd for VDS, which type of VLANs?



  • 18.  RE: Extract All vSS & VDS details for all vCenters

    Posted Nov 07, 2023 07:42 AM

    I'm using VDS and VLAN type.

    No Private or trunking vlans.

    With this part of code, I get what I want, but cannot integrate it to the code for the moment.

    $vlanId = $portGroup.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId

    Thank you



  • 19.  RE: Extract All vSS & VDS details for all vCenters

    Posted Nov 07, 2023 08:31 AM

    That is exactly what the snippet is doing for a VDS portgroup with a regular VLAN.
    Not sure why you wouldn't see the VLANid