VMware Cloud Community
cforest
Enthusiast
Enthusiast
Jump to solution

VMware Power CLI: how to get custom attributes for a datastore?

Hello,

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

Any thoughts?

Thank you!

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Unfortunately the Get-Annotation cmdlet doesn't handle datastores.
You will have to revert to the ExtensionData properties.

Something like this

$dsName = 'MyDS'

$ds = Get-Datastore -Name $dsName

$fields = @{}

$ds.ExtensionData.AvailableField | %{

    $fields.Add($_.Key,$_.Name)

}

$ds.ExtensionData.CustomValue.GetEnumerator() |

Select @{N='Name';E={$fields.Item($_.Key)}},Value


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

View solution in original post

2 Replies
LucD
Leadership
Leadership
Jump to solution

Unfortunately the Get-Annotation cmdlet doesn't handle datastores.
You will have to revert to the ExtensionData properties.

Something like this

$dsName = 'MyDS'

$ds = Get-Datastore -Name $dsName

$fields = @{}

$ds.ExtensionData.AvailableField | %{

    $fields.Add($_.Key,$_.Name)

}

$ds.ExtensionData.CustomValue.GetEnumerator() |

Select @{N='Name';E={$fields.Item($_.Key)}},Value


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

cforest
Enthusiast
Enthusiast
Jump to solution

LucD, it works! Thank you so much!

0 Kudos