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
10 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
lElOUCHE_79
Enthusiast
Enthusiast

@LucD 

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?

 

0 Kudos
LucD
Leadership
Leadership

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.


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

0 Kudos
lElOUCHE_79
Enthusiast
Enthusiast

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?

0 Kudos
LucD
Leadership
Leadership

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


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

lElOUCHE_79
Enthusiast
Enthusiast

Thanks 

 

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

0 Kudos