VMware Cloud Community
Munster99
Enthusiast
Enthusiast

Help with new-viproperty and 'datastore' object

Hey all

Was wondering if someone can help ?

I've been racking my brains and have come to the end of my tether as to what could be the problem. Issue is as follows :

New-VIProperty -ObjectType Datastore -Name _DSVersion_ -ValueFromExtensionProperty 'Info.Vmfs.Version'

New-VIProperty -ObjectType Datastore -Name _DSBlocksize_ -ValueFromExtensionProperty 'Info.Vmfs.BlockSizeMb'

All I'm trying to do is create a new vi-property that allows me to see the 'blocksize' and 'filesystem version' from the extensiondata object. I've done this numerous times before with other objects for other object types and they have been successful ?!?! However for this simple creation does NOT seem to be working and i cant figure it out ?!?!?

Any ideas anyone ?

Many thanks in advance

Munster99

(PS versions as below)

PowerCLI C:\> Get-PowerCLIVersion

PowerCLI Version
----------------
   VMware vSphere PowerCLI 5.0.1 build 581491
---------------
Snapin Versions
---------------
   VMware AutoDeploy PowerCLI Component 5.0 build 544967
   VMware ImageBuilder PowerCLI Component 5.0 build 544967
   VMware License PowerCLI Component 5.0 build 544881
   VMware vSphere PowerCLI Component 5.0 build 581435

Reply
0 Kudos
11 Replies
Grzesiekk
Expert
Expert

Smiley Happy i deleted my previous post as i was clearly not paying too much attension to the screen Smiley Wink here is the answer:

New-VIProperty -Name DSversionX -ObjectType Datastore -Value {        param($ds)    $ds.Extensiondata.info.Vmfs.Version    }

New-VIProperty -Name DSblockSizeMb -ObjectType Datastore -Value {        param($ds)    $ds.Extensiondata.info.Vmfs.BlockSizeMb    }

Greg

--- @blog https://grzegorzkulikowski.info
ykalchev
VMware Employee
VMware Employee

Hi,

ExtensionData.Info.Vmfs property is only available for VMFS datastores, so it's better to use Value and BasedOnExtensionProperty parameters in order to not get error for NFS datastores:

New-VIProperty -ObjectType Datastore -Name _DSBlocksize_ -Value { return $args[0].ExtensionData.Info.Vmfs.BlockSizeMb} -BasedOnExtensionProperty Info

BTW Info.Vmfs.Version property is already exposed in Datastore.FileSystemVersion

Regards,

Yasen

Yasen Kalchev, vSM Dev Team
Reply
0 Kudos
Munster99
Enthusiast
Enthusiast

Thanks a million guys - you were both right ! Smiley Happy

Aaah - that is making a tad more sense. As we do have some datastores configured as NFS. Not to try and get in another question here but whenever I do update my profile with these vi-properties i get the following error when i run any cmd - is this the norm or do you know what it might be related to please ??? :smileyblush:

Get-Datastore : 31/08/2012 12:42:11    Get-Datastore
At line:1 char:1
+ Get-Datastore | fl *
+ ~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-Datastore], InvalidProperty
    + FullyQualifiedErrorId : Client20_ExtensionDataHelper_GetExtensionDataByObjectContent_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

Even after I just enter in a simple 'get datastore' cmd i get the above after the result is outputted to the console screen ?!??!?

munster

Reply
0 Kudos
Grzesiekk
Expert
Expert

ykalchev,

  i have one question, why do we need to write "-BasedOnExtensionProperty Info" at the end.

i did this without the "-BasedOnExtensionProperty Info" and it works, is there any difference in this ? Would be great to understand this Smiley Wink

Does this mean that in the Info object is not there then this new property would not be included or is this about something else ?

Greg

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos
Grzesiekk
Expert
Expert

"but whenever I do update my profile with these vi-properties i get the  following error when i run any cmd - is this the norm or do you know  what it might be related to please ??? :smileyblush:"

If you issue command: get-VIProperty  what do you see ?

What do you mean exactly by 'update my profile' . Each time you will start powercli sessions, those new-properites are cleared and you have to issue those commands again in order them to show new properties.

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos
Munster99
Enthusiast
Enthusiast

Sorry Grzesiekk

What i meant to say was - I enter all these properties into my "microsoft_powershell_profile" so i can reuse all these properties from a powershell cmd window. Some exmaples as shown below :


New-VIProperty -ObjectType vmHost -Name _CPUMHz_ -ValueFromExtensionProperty 'summary.hardware.cpumhz' -Force
New-VIProperty -ObjectType vmHost -Name _NumOfNics_ -ValueFromExtensionProperty 'summary.hardware.NumNics' -Force
New-VIProperty -ObjectType vmHost -Name _NumOfHBAs_ -ValueFromExtensionProperty 'summary.hardware.NumHBAs' -Force
New-VIProperty -ObjectType vmHost -Name _BIOSInfo_ -ValueFromExtensionProperty 'hardware.biosinfo.biosversion' -Force
New-VIProperty -ObjectType vmHost -Name _NumOfDatastores_ -ValueFromExtensionProperty 'COUNT Datastore' -Force
New-VIProperty -ObjectType vmHost -Name _Boottime_ -ValueFromExtensionProperty 'summary.runtime.boottime' -Force
New-VIProperty -ObjectType vmHost -name _AvgCPUUsage24Hr_ -Value {“{0:f2}” -f ($args[0]|Get-Stat -stat cpu.usage.average|Where {$_.Instance -eq “”}|Measure-Object -Property Value -Average).Average} -Force

New-VIProperty -ObjectType Datastore -Name _DSNumOfVMs_ -ValueFromExtensionProperty 'COUNT vm'

(They come in very handy when you are using the command line. ) Smiley Wink

Now the wierd thing is since this list is getting bigger with more and more 'viproperties' being added regularly. I have noticed that when i type in a get-datastore command in my command window I get the error i mentioned earlier.

Ps - yes the filesystem version is present already but the blocksize will still be needed

thanks

munster

Reply
0 Kudos
ykalchev
VMware Employee
VMware Employee

Hi Greg,

BasedOnExtensionProperty is used for performance optimization. ExtensionData property is on-demand property - it is initialized on the first use.

When VIProperty is calculated, if BasedOnExtensionProperty parameter is not specified the entire ExtensionData object is retrieved from the server.

When specifying BasedOnExtensionProperty only these properties are retrieved. It will reduce the execution time and network traffic especially for large objects like VirtualMachine.

Regards,

Yasen

Yasen Kalchev, vSM Dev Team
Reply
0 Kudos
Grzesiekk
Expert
Expert

Yasen,

  one more question because i got really confused about this new-viproperty. How is this possible ?

New-VIProperty -ObjectType Datastore -Name _DSNumOfVMs_ -ValueFromExtensionProperty 'COUNT vm'

$datastore.Extensiondata has only object in it called vm, which keeps vms which resides on this DS. How come it is possible to use this formula

COUNT vm here ? I mean what is count here? powershell does not have command like count as far as i know 😕 and yet when i will type this it will work.

Greg

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos
Grzesiekk
Expert
Expert

get-viproperty

maybe you have some wrong new-viproperty inserted ? Otherwise no clue.

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos
ykalchev
VMware Employee
VMware Employee

With the -ValueFromExtensionProperty parameter you can use a simple mapping or one of the aggregation functions: SUM, AVERAGE or AVG, MIN, MAX, UNIQUE, COUNT. This eliminates the need of setting up a complete script block.

You can check examples in the Luc's article:http://www.lucd.info/2010/07/13/powercli-4-1-brings-the-new-viproperty-cmdlet/

Yasen Kalchev, vSM Dev Team
Reply
0 Kudos
Grzesiekk
Expert
Expert

"

Properties from the API object with aggregation functions.

Quite often the actions you have to take for the -Value parameter are simple one-to-one mappings or any of the following aggregation functions: SUM, AVERAGE or AVG, MIN, MAX, UNIQUE, COUNT.

"

Ok, any idea from where those aggregate functions are comming ? IT's awesome that you can just type count "property" but i thought i would have to do  $obj.vms.count  for example, i just don't get from where we have received thsoe aggregation functions.

Greg

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos