VMware Cloud Community
shaheer_sham
Contributor
Contributor

Determine vCenter name from VM or ESX Host

Hi All,

Am trying to determine a way to fetch vCenter name for the VM / ESX host is registered to. Is there a vSphere CLI script I can use ?

This is needed because we receive an alert from monitoring agents saying so and so VM or so and so ESX server is down. Rather than hopping between multiple vCenters we should a have more simpler way to find vCenter name through some mechanism. Please advise.

thanks a ton in advance.

Shaheer

Reply
0 Kudos
3 Replies
MauroBonder
VMware Employee
VMware Employee

Welcome!

Discussion moved from VMware vCenter™ to VMware vSphere™ PowerCLI

*Please, don't forget the awarding points for "helpful" and/or "correct" answers. *Por favor, não esqueça de atribuir os pontos se a resposta foi útil ou resolveu o problema.* Thank you/Obrigado
Reply
0 Kudos
Sreejesh_D
Virtuoso
Virtuoso

welcome shaheer!!

this is what we've done in our environment to address the similer concern.

http://pingforinfo.com/powercli-sccript-for-exporting-vm-details-to-html/

we've autamated it with the help of windows task scheduler. Now we have the VM inverntory dailiy. So whenecer a VM failurre alert comes its just the mater of searching the inventory (HTML) file with the VM name. 

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership

The vCenter Server name is in the Uid property. You can use the string Split() method to extract the vCenter Server name:

Get-VM | Select-Object Name,@{N="vCenter";E={$_.Uid.Split('@')[1].Split(':')[0]}}
Get-VMHost | Select-Object Name,@{N="vCenter";E={$_.Uid.Split('@')[1].Split(':')[0]}}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition