PowerCLI

 View Only
  • 1.  How to get VMhost for a VM template (from get-view)

    Posted Jun 06, 2017 06:40 PM

    Hi all -

    I'm using PowerCLi 6.5.

    I created a function that uses get-view to report a lot of info about our VM templates (e.g., name, description, filename, datastores, vm folder, version, CPU, memory, network, guest info, etc etc etc) but can't find the vmhost name on which the template currently resides (and then the vmhost cluster).

    $TemplateView = Get-View -ViewType VirtualMachine -Filter @{'Name'="mytemplate"}

    I have gone through all the available properties recursively  to try & see what I can get, but vmhost doesn't seem to be among them. I can see the vmhost in the web client, so I know it knows it has one!

    I also see this, but can't figure out how to do anything with it (I'm still a bit fuzzy on how to use managedobjectreferences):

    $Templateview.summary.vm

    Type           Value 

    ----           ----- 

    VirtualMachine vm-1942

    Hep?

    Thanks,

    Paula

    PS: Also, I can't figure out how to insert code blocks in here...some guidance there would be nice too  :smileywink:



  • 2.  RE: How to get VMhost for a VM template (from get-view)

    Posted Jun 06, 2017 07:09 PM

    Try like this

    Get-View -ViewType VirtualMachine -Filter @{'Name'="mytemplate"} |

    Select Name,@{N='VMHost';E={Get-View -Id $_.Runtime.Host -Property Name | Select -ExpandProperty Name}}

    See Some ways to enter PowerCLI code under the new forum SW for inserting code.



  • 3.  RE: How to get VMhost for a VM template (from get-view)

    Posted Jun 08, 2017 11:48 PM

    Hi Luc - brilliant! I still don't fully understand all the magical things in get-view and the property names often confuse me; I knew this information had to be in there somewhere. Thank you thank you thank you. :smileyhappy:

    Paula



  • 4.  RE: How to get VMhost for a VM template (from get-view)

    Posted Jun 09, 2017 04:35 AM

    The Property parameter is a kind of filter.

    If you leave it out, all the properties of the vSphere object will be returned.

    If you use it, only the properties you specify will be populated in the returned vSphere object.

    It's a speed of execution consideration, the use of the Property parameter should make the Get-View cmdlet faster. Which can be important especially if you need to run against bigger environments.