Highlighted
Expert
Expert

strange behaviour of get-viobjectbyview

$a=get-vm testvm|get-view

PowerCLI C:\> $a|Get-VIObjectByVIView
Get-VIObjectByVIView : 10/30/2012 12:57:46 PM    Get-VIObjectByVIView        Object reference not set to an instance of an object.

PowerCLI Version
----------------
   VMware vSphere PowerCLI 5.0.1 build 581491
---------------

I think that this has worked previously 😕

PowerCLI C:\> $a.moref|Get-VIObjectByVIView

Name                 PowerState Num CPUs Memory (MB)
----                 ---------- -------- -----------
testvm               PoweredOff 1        4096

When i pass moref directly to get-viobjectbyview then it executes without error. from help :

-MORef <ManagedObjectReference[]>
    Specify the managed object ID, obtained from a property of another mana
    ged object or a view.

    Required?                    true
    Position?                    1
    Default value
   Accept pipeline input?       true (ByValue)
    Accept wildcard characters?  false

From other help:

"

     -- ByValue: Parameters that accept input "by value" can accept piped objects
        that have the same .NET type as their parameter value or objects that can be
        converted to that type. 

        For example, the Name parameter of Start-Service accepts pipeline input
        by value. It can accept string objects or objects that can be converted to
        strings.
"

So i thought it should discover the moref by itself , or i am thinking in wrong way?

Can somebody check if it works on different powercli versions ?

A friend of mine told me that it works for him , he runs this version:

PowerCLI Version
----------------
   VMware vSphere PowerCLI 5.0 build 435427
Is it possible that VMware vSphere PowerCLI 5.0.1 build 581491 is bugged ?
--- @blog https://grzegorzkulikowski.info
Tags (1)
0 Kudos
2 Replies
Highlighted
User Moderator
User Moderator

Yes, works without a problem in PowerCLI 5.1 build 793510


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

Highlighted
Expert
Expert

Just had another info from other friend, he was using the same powercli version as i. He also gets the same error. I think it's time to update powercli in that case Smiley Wink

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