set-Annotation -Entity (Get-VDPortgroup -name "k8s") -CustomAttribute "CIDR" -Value "24"
Results in:
Cannot convert the "k8s" value of type "VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl" to type "VMware.VimAutomation.ViCore.Types.V1.Inventory.Invent
oryItem"
$p=Get-VDPortgroup -name "k8s"
Set-Annotation -Entity [VMware.VimAutomation.Vds.Types.V1.VDPortgroup]$p -CustomAttribute "CIDR" -Value "24"
Results in:
Set-Annotation Value cannot be found for the mandatory parameter Entity
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)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What does this return?
Get-VDPortgroup -Name 'k8s'
(Get-VDPortgroup -Name 'k8s').GetType()
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Get-VDPortgroup -Name 'k8s':
Name NumPorts PortBinding
---- -------- -----------
k8s 16 Static
(Get-VDPortgroup -Name 'k8s').GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
False False VmwareVDPortgroupImpl VMware.VimAutomation.Vds.Impl.V1.VDPortgroupImpl
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)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Fantastic, thank you!