Automation

 View Only
  • 1.  Get-view -RelatedObject question

    Posted Jan 12, 2016 12:27 PM

    Hello,

    has anybody used get-view to generate the related object lists ? Like there is in vsphere web client for example, you can select VM, click the related objects tab, and you will see associations to networks or datastores.

    Get-view has the parameter -relatedObject  which is of ViewBaseMirroredObject type.  I have no idea where do i get that value for this parameter. Has anybody tried to do this ?

    Thank you in advance

    Greg



  • 2.  RE: Get-view -RelatedObject question
    Best Answer

    Posted Jan 12, 2016 12:57 PM

    Afaik, the RelatedObject parameter on the Get-View cmdlet has nothing to do with the Related Objects tab in the Web Client.

    The RelatedObject parameter is to link cloud objects with vSphere objects.

    See Alan's post called Relating vCloud Director to vCenter in PowerCLI on the subject.



  • 3.  RE: Get-view -RelatedObject question

    Posted Jan 12, 2016 01:26 PM

    Ohh, i see,  thanks Luc. Any chance there is a easy way to discover the related objects like the vsphere web client does it in powercli ?

    Greg



  • 4.  RE: Get-view -RelatedObject question

    Posted Jan 12, 2016 01:51 PM

    Funny you should ask that, just last weekend, I was playing with this.

    Although I believe that the Related Objects in the Web Client are hard-coded, I wanted a script that would show me all the objects for which a specific object had pointers (MoRefs).

    I came up with something like this (draft, not optimised) for VMHosts.

    foreach($esx in Get-View -ViewType HostSystem){

        $esx.PSObject.Properties |

            where{($_.TypeNameOfValue -eq 'VMware.Vim.ManagedObjectReference' -or

                  $_.TypeNameOfValue -eq 'VMware.Vim.ManagedObjectReference[]') -and $_.Value} | %{

            Get-View -Id $_.Value -Property Name -ErrorAction SilentlyContinue |

            where{$_.Name} |

            Select @{N='VMHost';E={$esx.Name}},Name,@{N='Type';E={$_.GetType().Name}}

        }

    }