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:
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
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
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
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
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?
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
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?
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
Thanks
to the previous script can we add at least IP adress?
Hello @LucD
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?
It is rather simple, I didn't implement that in the code at the time.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
😂😂😂😂
Thank you I will try to add that include it
I didn't find the way to show the information for ActiveNic/StandByNic
would you please assist on this?