SCharchouf
Hot Shot
Hot Shot

Extract All vSS & VDS details for all vCenters

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

 

 

 

 

Labels (2)
Tags (1)
0 Kudos
5 Replies
LucD
Leadership
Leadership

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.


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot

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

 

0 Kudos
LucD
Leadership
Leadership

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
                    }
                }
            })
        }
    }
}

 


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

SCharchouf
Hot Shot
Hot Shot

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
0 Kudos
LucD
Leadership
Leadership

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.


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

0 Kudos