Quickly find where your VCenter VM is running using PowerShell and PowerCLI
VCenter is the glue to a solid VSphere environment, so if it stops working so do other components like Vmotion and DRS (pretty important). Most environments run Vcenter on a VM within VSphere, not a physical box. So, if Vcenter stops working to the point where it cannot be accessed via the web client, Windows client, or PowerShell, you will probably want to access the VM console to troubleshoot. Chances are though, you do not keep tabs on what ESXi host the Vcenter VM is running on. If you have more than a few ESXi hosts in your environment, trying to find which host the VCenter VM is running on can be painful if done manually. So instead of going through that hassle, lets automate that.
To do this lets use PowerShell and PowerCLI to build a small, simple function to access each ESXi host to see if the VCenter VM is running.
The flow of the function is fairly simple:
- Connect to the ESXi host
- Attempt to find the VCenter VM by name
- If the VCenter VM is found, it writes the ESXi host to output
- If it does not find VCenter, move on to the next ESXi host
Looks like our VCenter is running on host1.
There we have it. A very simple PowerShell function to find our VCenter.