Automation

 View Only
  • 1.  Why does this fail?

    Posted Jun 26, 2008 02:23 PM

    I am trying to list a folder's child entities when they are VMs:

    ( Get-View ( Get-Folder "Colors" ).ID ).ChildEntity | Get-View $_.ID

    I get this error:

    Get-View : Cannot bind argument to parameter 'MoRef' because it is null.

    At line:1 char:63

    + ( Get-View ( Get-Folder "Colors" ).ID ).ChildEntity | Get-View <<<< $_.ID

    This happens a lot. The second Get-View always thinks the session is not authenticated.



  • 2.  RE: Why does this fail?

    Broadcom Employee
    Posted Jun 26, 2008 03:07 PM

    ChildEntity property of the Folder object is ManagedObjectReference array so you can pass it to Get-View cmdlet. Get-View MoRef parameter accepts both string ID and ManagedObjectReference objects

     ( Get-View ( Get-Folder "Colors" ).ID ).ChildEntity | Get-View
    

    Regards,

    Yasen



  • 3.  RE: Why does this fail?

    Posted Jun 26, 2008 03:45 PM

    Thank you for the response : ) Your suggestion is what I was already

    doing, but there appears to be a bug where multiple Get-View

    invocations fail.

    (FYI - I know how things are supposed to work, they just aren't

    working that way : )

    --

    -a

    "condensing fact from the vapor of nuance"



  • 4.  RE: Why does this fail?

    Broadcom Employee
    Posted Jun 26, 2008 05:24 PM

    Sorry If I bothered you with my replay I've just wanted to help. But the idea of my post was that the error

    Get-View : Cannot bind argument to parameter 'MoRef' because it is null.

    At line:1 char:63

    + ( Get-View ( Get-Folder "Colors" ).ID ).ChildEntity | Get-View &lt;&lt;&lt;&lt; $_.ID

    is caused by the $_.Id at the end of the line. ( I've got completely the same error on my test env.)

    From you latest comment I understand that this is not the actual problem you face. You can check thread, may be you have similar problem.

    Please ignore my post if you've already check that. As I said I'm just trying to help :smileyhappy:

    Thanks,

    Yasen



  • 5.  RE: Why does this fail?

    Posted Jun 26, 2008 06:11 PM

    I'm not convinced that there is an actual bug in this use of the Get-View cmdlet.

    As you said in your first reply the childEntity property is an array of ManagedObjectReference elements.

    Even if there is only 1 child in the "Colors" folder the property is still an array (albeit of 1 element).

    You can check with

    (( Get-View ( Get-Folder "Colors" ).ID ).ChildEntity).Count
    (( Get-View ( Get-Folder "Colors" ).ID ).ChildEntity).GetType()
    

    If you loop through the elements of the array the Get-View cmdlet functions correctly

    ( Get-View ( Get-Folder "Colors" ).ID ).ChildEntity | %{Get-View $_}
    

    In this case the $_ represents each object (which is ManagedObjectReference) in the ForEach-Object loop.

    What I don't get is why this is working

    ( Get-View ( Get-Folder "Colors" ).ID ).ChildEntity | Get-View
    

    Is there an implicit loop through all the elements in the array?

    By the pipe or by the Get-View cmdlet?



  • 6.  RE: Why does this fail?

    Posted Jun 26, 2008 06:22 PM

    This does not work for me:

    ( Get-View ( Get-Folder "Colors" ).ID ).ChildEntity | %{ Get-View $_ }
    

    or

    ( Get-View ( Get-Folder "Colors" ).ID ).ChildEntity | %{ Get-View $_.ID }
    

    or

    ( Get-View ( Get-Folder "Colors" ).ID ).ChildEntity | %( Get-View $_ )
    

    or

    ( Get-View ( Get-Folder "Colors" ).ID ).ChildEntity | %( Get-View $_.ID )
    

    I get the following output:

    Get-View : Cannot bind argument to parameter 'MoRef' because it is null.

    At line:1 char:65 + ( Get-View ( Get-Folder "Colors" ).ID ).ChildEntity | %{Get-View <<<< $_}

    And just so you don't think my folder "Colors" is empty:



  • 7.  RE: Why does this fail?

    Posted Jun 26, 2008 06:28 PM
    > ( Get-View ( Get-Folder "Colors" ).ID ).ChildEntity | %{ Get-View $_ }
    > 

    I may get thwapped for this but oh well. The behavior of the Get-View cmdlet is going to be changed by release, making an operation like this much easier. For example:

    Get-Folder Foo | Get-VM | Get-View

    or, to get all contents (including VMs)

    Get-Folder Foo | Get-Inventory | Get-View

    There's also a cmdlet for going the other way and that also works in the pipeline...

    Hal Rottenberg

    Co-Host, PowerScripting Podcast (http://powerscripting.net)

    Message was edited by: halr9000, fixed typo



  • 8.  RE: Why does this fail?

    Posted Jun 26, 2008 06:32 PM

    Mystery :smileywink:

    To show that it works for me, the foreach loop in my test environment

    And my test folder with 2 guests

    Could it be that we are using different versions and/or builds ?



  • 9.  RE: Why does this fail?

    Posted Jun 26, 2008 06:42 PM

    I'll show you mine if you show me yours:

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> Get-VIToolkitVersion

    VI Toolkit Version

    -


    VMware VI Toolkit for Windows 1.0 (Beta) build 81531

    Same version, same build. Very odd. Wait, I bet I know what it is. Be right back.



  • 10.  RE: Why does this fail?

    Posted Jun 26, 2008 06:44 PM

    Works. The Get-View command only works the first time with pass-through auth. Once I switched to logging in with a username and password it worked.



  • 11.  RE: Why does this fail?

    Posted Jun 26, 2008 06:14 PM

    Yasen,

    I am so sorry that I offended you. My intent was not to be rude at all, and it seems I came across that way. I sincerely thank you for your response. I am about to post another reply to LucD. I posted incorrect code at first, which is why when I read your response I did not understand why you were posting the same code I thought I posted : )