3 Replies Latest reply on Jan 12, 2016 5:50 AM by LucD

    Get-view -RelatedObject question

    Grzesiekk Expert


      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


        • 1. Re: Get-view -RelatedObject question
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          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.

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Get-view -RelatedObject question
            Grzesiekk Expert

            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 ?



            • 3. Re: Get-view -RelatedObject question
              LucD Guru
              vExpertUser ModeratorsCommunity Warriors

              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}}



              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz