Closed atkinsroy closed 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 += '--'
}
}
.
.
.
I see the issue.
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
Operating System
Windows
PowerShell Version
PowerShell Modules
Additional Context
No response
Before submitting