I am trying to get a custom attribute value for my datastore, but bumping into an issue with type incompatibility. Is there anything I am doing wrong below, and how to fix it?

PowerCLI C:\> $ds = Get-Datastore -Name YK
PowerCLI C:\> $ds

Name                               FreeSpaceGB      CapacityGB
----                               -----------      ----------
YK                                  14,528.467      14,901.750

PowerCLI C:\> Get-Annotation -Entity $ds -CustomAttribute ykcustattr_global
Get-Annotation : Cannot bind parameter 'Entity'. Cannot convert the "YK" value of type "VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.VmfsDatastoreImpl" to type "VMware.VimAutomation.ViCore.Types.V1.Inventory.InventoryItem".
At line:1 char:24
+ Get-Annotation -Entity $ds -CustomAttribute ykcustattr_global
+                        ~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Annotation], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetAnnotation

Note 1: I am able to get a custom attribute for a virtual machine, cluster and host. The problem is with the Datastore only.

Note 2: I guess the problem is that Get-Datastore returns Datastore object, while Get-Annotation expects InventoryItem object for -Entity. It is not clear if it is possible to do a cast/transformation or anything like that.

VMware vCenter version: 6.5

Thank you!


I got an answer on the VMware forum and decided to post it here. Briefly, the problem exists, but there is a workaround:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.