VMware Cloud Community
ISYS2
Enthusiast
Enthusiast

Get-VIObjectByVIView returns incomplete ManagedObject Reference ..... Sometimes!

I am getting a strange problem with ManagedObject References (MOR)

Consider the following two snippets.

1.

$str = Get-Datastore Dstore1 | Get-View
$hst = Get-VIObjectByVIView $str.Host[0].key
$vm = new-vm -Name VM1 -VMHost $hst -Template tmp1 -Datastore Dstore1

2.

$clus = Get-View -ViewType ClusterComputeResource -Filter @{"Name" = Cluster1}
$hst = Get-VIObjectByVIView $clus.Host[0]
$vm = new-vm -Name VM1 -VMHost $hst -Template tmp1 -Datastore Dstore1

Snippet 1 works fine. Snippet 2 fails because the $hst MOR is incomplete.

Even though $str.Host[0].key (in Snippet1) and $clus.Host[0] (in Snippet2) look identical, when they are converted by Get-VIObjectByVIView they result in different sets of information.

I would like to use the Snippet 2 method as Get-View is a lot quicker than Get-Datastore, Get-Network etc and I am crunching through some big lists.

Anyone got any thoughts or ideas

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership

I reported a similar problem with the CustomFields property of VirtualMachine objects.

The answer was that this was fixed in the soon-to-be-released PowerCLI (the new name for the VITK) that will come with vSphere.


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

ISYS2
Enthusiast
Enthusiast

Thanks for this. I suspected that this may be the case. I do hope that the PowerCLI will be thoroughly tested before it is released. The VITK is good but these little inconsistencies are very frustrating.

Reply
0 Kudos