AsBuiltReport / AsBuiltReport.VMware.vSphere

Repository for AsBuiltReport VMware vSphere module
https://www.asbuiltreport.com
MIT License
112 stars 39 forks source link

Host Network Section - NSX-T virtual switch portgroup labels are erroneously associated with a VMKernel port #118

Closed atkinsroy closed 8 months ago

atkinsroy commented 9 months ago

Bug description

In the VMKernel adapters section of the document, some VMkernel ports have all labels associated with them, when there should be none. I've isolated the issue to the following code:

'Network Label' = & { if ($_.Spec.Portgroup) { $script:pg = $_.Spec.Portgroup } else { $script:pg = Get-View -ViewType DistributedVirtualPortgroup -Property Name, Key -Filter @{'Key' = "$($_.Spec.DistributedVirtualPort.PortgroupKey)" } | Select-Object -ExpandProperty Name } $script:pg }

The -filter accepts a value. In my case there is no PortgroupKey, and there is therefore no filter so all portgroup labels are displayed. This is an NSX-T managed switch, so this might be the reason that perhaps you've not seen this before.

Command-line input

New-AsbuiltReport -Report VMware.vSphere

Steps to reproduce

$View = Get-VMhost -Server X | Get-View $NetSys = Get-View $View.ConfigManager.NetworkSystem $Vnic = $NetSys.NetworkInfo.Vnic ($Vnic | ? Device -eq 'vmk0').Spec.DistributedVirtualPort.PortgroupKey # This has a value, so -Filter above works.

($Vnic | ? Device -eq 'vmk10').Spec.DistributedVirtualPort.PortgroupKey # This has no value, so -Filter above displays all portgroup labels.

Expected behaviour

In the vSphere client, these kernel ports show a dash under network label. So I guess that's the expected behaviour here too.

Screenshots

image

image

Operating System

Windows

PowerShell Version

image

PowerShell Modules

image

Additional Context

No response

Before submitting

atkinsroy commented 9 months ago

Here's how I've tackled it. This appears to work in an NSX-T environment:

foreach ($Vmk in $VmKernel) {
            if ($Vmk.Spec.PortGroup) {
                $NetLabel += $Vmk.Spec.PortGroup
            }
            else {
                if ($Vmk.Spec.DistributedVirtualPort.Portgroupkey) {
                    $NetLabel += ($DvPortGroup | Where-Object Key -eq $Vmk.Spec.DistributedVirtualPort.Portgroupkey).Name
                }
                else {
                    $NetLabel += '--'
                }
            }
.
.
.
tpcarman commented 9 months ago

I see the issue.

image

image