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?
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
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
LucD:
Either. Although I tend to use the PowerCLI cmdlets as I still have diffuculty in wrapping my head around Get-View.
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