vCenter 4.1 Update 2
PowerCLI 5.1 Release 1
I can successfully retrieve VMHost's IDs via:
Get-VMHost | Select Name,@{N='VMHostID';E={$_.ExtensionData.Config.Host.Value}}
I can also (appear) to successfully create a VIProperty for VMHostID with:
New-VIProperty -Name VMHostID -ObjectType VMHost -ValueFromExtensionProperty Config.Host.Value
However, when I try to use it I am greeted with an exception and no values in VMHostID
Get-VMHost | Select Name,VMHostID
CategoryInfo : [Get-VMHost], InvalidProperty
FullyQualifiedErrorId: Client20_ExtensionDataHelper_GetExtensionDataByObjectContent_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost
I get the same result on multiple vCenters of the same version. Creating VIProperties from other VMHost extension properties work without issue.
Is anyone able to reproduce this?
With a slight change it works like that, just leave out the Value property in the BasedOnExtensionProperty.
New-VIProperty -Name VMHostID -ObjectType VMHost -Value { param($vmhost) $vmhost.ExtensionData.Config.Host.Value
} -BasedOnExtensionProperty Config.Host -force
Update: this looks a lot like a problem I once had with the Get-View cmdlet.
When I specified the MoRef on the Property parameter, I also got an exception.
Get-View -ViewType HostSystem -Property MoRef
One of the PowerCLI Dev guys explained that "MoRef, ... are client side properties and it is not possible to use them as argument for Property parameter". I wonder if this problem is not similar ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Jonathan,
I get the same error with PowerCLI 5.1 Release 1 and vCenter 5.1. It looks like a bug in the -ValueFromExtensionProperty parameter. If I do it like this:
New-VIProperty -Name VMHostID -ObjectType VMHost -Value { param($vmhost) $vmhost.ExtensionData.Config.Host.Value } -force
it will work good.
Thanks for confirming.
I already tried the below, but I included the -BasedOnExtensionProperty parameter and still got the same error. Could you confirm that also?
i.e.
I will need to test it tomorrow without the -BasedOnExtensionProperty parameter.
With a slight change it works like that, just leave out the Value property in the BasedOnExtensionProperty.
New-VIProperty -Name VMHostID -ObjectType VMHost -Value { param($vmhost) $vmhost.ExtensionData.Config.Host.Value
} -BasedOnExtensionProperty Config.Host -force
Update: this looks a lot like a problem I once had with the Get-View cmdlet.
When I specified the MoRef on the Property parameter, I also got an exception.
Get-View -ViewType HostSystem -Property MoRef
One of the PowerCLI Dev guys explained that "MoRef, ... are client side properties and it is not possible to use them as argument for Property parameter". I wonder if this problem is not similar ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, that is great; works fine with the adjustment you suggested. I really wanted to use the -BasedOnExtensionProperty parameter because it makes a performance difference of about 10x.
One to add to the VIProperty module?
Will add it.
There are a few more on the stack, I will need to do a new version.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference