VMware Cloud Community
Grzesiekk
Expert
Expert
Jump to solution

Get-view -RelatedObject question

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

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

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

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos