Highlighted
Expert
Expert

Get-view -RelatedObject question

Jump to solution

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
0 Kudos
1 Solution

Accepted Solutions
Highlighted
User Moderator
User Moderator

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

0 Kudos
3 Replies
Highlighted
User Moderator
User Moderator

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

0 Kudos
Highlighted
Expert
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 ?

Greg

--- @blog https://grzegorzkulikowski.info
0 Kudos
Highlighted
User Moderator
User Moderator

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

0 Kudos