VMware Cloud Community
aenagy
Hot Shot
Hot Shot
Jump to solution

How to determine the vCenter instance for a given vSphere entity

I frequently need to generate output or act on various vSphere entities (virtual machines, vSphere clusters, SDRS clusters, etc) across multiple vCenter instances. I can easily run scripts that will iterate through all virtual machines after connecting to multiple vCenter instances using Connect-VIServer.  I haven't been able to find anything in searching he output from Get-Member. Following the Parent property recursively (show parent object from get-view -ViewType HostSystem) does not lead to the name of the vCenter insance. What I would like to know is if there is a way of determining which insance of vCenter is managing a particular entity.

OR

Is this a situation where it is not possible to determine the instance of vCenter, but instead the script must iterate through $global:defaultviservers and use the Server parameter?

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this (I only show for a VMHost, but most of the other object should offer the same possibility).

# .Net object

$esx = Get-VMHost -Name MyEsx

$esx.Uid.Split(':')[0].Split('@')[1]

# vSphere object

$esx = Get-View -ViewType HostSystem -Filter @{'Name'='MyEsx'}

$esx.Client.ServiceUrl.Split('/')[2]


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

Are you using the Get-View cmdlet or the regular PowerCLI cmdlets to get the objects ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
aenagy
Hot Shot
Hot Shot
Jump to solution

LucD:

Either. Although I tend to use the PowerCLI cmdlets as I still have diffuculty in wrapping my head around Get-View.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this (I only show for a VMHost, but most of the other object should offer the same possibility).

# .Net object

$esx = Get-VMHost -Name MyEsx

$esx.Uid.Split(':')[0].Split('@')[1]

# vSphere object

$esx = Get-View -ViewType HostSystem -Filter @{'Name'='MyEsx'}

$esx.Client.ServiceUrl.Split('/')[2]


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos