Got it working, for anyone else looking:
$customFieldMgr = Get-View ($global:DefaultVIServer.ExtensionData.Content.CustomFieldsManager)
# Retrieve custom attributes from vcenter inventory and create lookup table
$customKeyLookup = @{}
$customNameLookup = @{}
$customFieldMgr.Field | % {
$customKeyLookup.Add($_.Key, $_.Name)
$customNameLookup.Add($_.Name, $_.Key)
}
$networkView = Get-View -ViewType Network -Property Name,Value -Filter @{ "name" = $($vmotionPortgroupObject.name) }
foreach($thisIndex in 0..$($networkView.Value.Key.Length-1)) {
Write-Host "Portgroup $($vmotionPortgroupObject.name) has custom attribute $($customKeyLookup[$networkView.Value[$thisIndex].Key]) with value: $($networkView.Value[$thisIndex].Value)"
}
Original Message:
Sent: Jun 25, 2025 02:28 AM
From: pbknl
Subject: Set-Annotation on VDPortgroup fails
I have the same issue but then for retrieving a custom attribute that's already set on a portgroup.
$test = Get-VDPortGroup -VDSwitch $dvsManagementObject -Name "test-portgroup"
Get-Annotation -Entity $test
Get-Annotation: Cannot bind parameter 'Entity'. Cannot convert the "test-portgroup" value of type "VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl" to type "VMware.VimAutomation.ViCore.Types.V1.Inventory.InventoryItem".
I've tried converting the workaround but can't get it working for retrieving attributes.
Any change you can push me in the right direction?
Thanks!
P
Original Message:
Sent: Apr 05, 2024 01:03 PM
From: LucD
Subject: Set-Annotation on VDPortgroup fails
Seems Custom Attributes are not implemented for all inventory items.
Also the vdPortgroup object is not derived from an inventory item in the same way as for example a VM is.
In any case, you can use the API to fix this
$caName = 'CIDR'$caValue = '24'$vdpgName = 'k8s'$ca = Get-CustomAttribute -Name $caName$pg = Get-VDPortgroup -Name $vdpgName$si = Get-View ServiceInstance$fldMgr = Get-View -Id $si.Content.CustomFieldsManager$fldMgr.SetField($pg.Id, $ca.Key, $caValue)