VMware Cloud Community
Munster99
Enthusiast
Enthusiast

viproperty question

Hi all

I've created the following viproperty to tell me if a datastore is 'local' or 'SAN' based. It 'seems' to be working however I thought I would get a second opinion from you guys

New-VIProperty -ObjectType Datastore -Name _LOCALorSAN -ValueFromExtensionProperty 'info.vmfs.local' -Force

When i call up a SAN datastore and ask to see its properties its shows up fine and reports that it is NOT local. However when I ask to see a 'local' datastore it still shows that it is TRUE (which is correct) but shows an error (see below).

Get-Datastore : 18/01/2014 17:18:45Get-Datastore    InvalidProperty(info.vmfs.local):

At line:1 char:1

+ Get-Datastore *7641* | fl *

+ ~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo      : NotSpecified: (:) [Get-Datastore], InvalidProperty
+ FullyQualifiedErrorId : Client20_ExtensionDataHelper_GetExtensionDataByObjectContent_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

Have i done something wrong ?

Thanks in advance

Munster

Tags (1)
0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership

I don't know why your command does not work because it looks right to me. You can use the following alternative:

New-VIProperty -Name _LOCALorSAN -ObjectType Datastore `

  -Value {

    param($ds)

    $ds.ExtensionData.Info.Vmfs.Local

  } -Force

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
LucD
Leadership
Leadership

This is because the Info.Vmfs.Local property is not present for all derived Datastore objects.

In Vitali's post called Ability to customize VI objects, it says (and I quote) :

" Because SDK objects are hierarchical related it is possible to define custom property

on ancestor type and all its inheritors will have the property too."

If we look at a sample new property on the datastore object, we can demonstrate this behavior.

ds-inheritance.png

The new property is not only present on the Datastore object, but also on the derived ones !

My advise, if you need to define a new property, that is based on a subset of the object, in other words not present in all derivatives of the object, do it with a script block, not with the ValueFromExtensionProperty option.


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

0 Kudos