- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
$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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks
to the previous script can we add at least IP adress?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is rather simple, I didn't implement that in the code at the time.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
![]()
![]()
![]()
Thank you I will try to add that include it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I didn't find the way to show the information for ActiveNic/StandByNic
would you please assist on this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello LucD,
I'm somehow still getting the vlan ID colon empty. Any hint?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you using VSS or VDS, or a mix?
ANd for VDS, which type of VLANs?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference