VMware Cloud Community
Cambio
Contributor
Contributor
Jump to solution

Set-Annotation on VDPortgroup fails

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

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

What does this return?

Get-VDPortgroup -Name 'k8s'
(Get-VDPortgroup -Name 'k8s').GetType()


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Cambio
Contributor
Contributor
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
Cambio
Contributor
Contributor
Jump to solution

Fantastic, thank you!

0 Kudos