Adding and re-adding ESX servers to VirtualCenter
Hosts can get disconnected for a variety of reasons. One common reason is that the host was imported into another instance of VirtualCenter, since only one VirtualCenter can manage an ESX host at a time.
Here's what a host (in my case, 10.16.83.242) looks like when it's disconnected:
In other words a disconnected host appears in inventory but is unmanagable. If you have a lot of disconnected hosts, here's a PowerShell script you can use to automatically reconnect every host (new and improved with real-world customer feedback! Thanks Tom!):
# Reconnect all hosts in VirtualCenter. Connect first using Get-VIServer.
# If you need a password, set it here.
$password = $null
get-vmhost | where { $_.State -eq "Disconnected" -or $_.State -eq "notResponding" } |
% {
$view = get-view $_.ID
$arg = new-object VMware.Vim.HostConnectSpec
$arg.userName = "root"
$arg.password = $password
$arg.force = $true
if ($_.State -eq "notResponding") {
$return = $view.DisconnectHost_Task()
wait-task $return
}
$view.ReconnectHost_Task($arg)
}
|
This script automatically detects any disconnected host and reconnects it (be sure you connect to VirtualCenter before running it though!) On the first line, the script also allows setting a password Sometimes you can't reconnect a host without a password, usually because the password has been changed. If this applies to you, set the password here and you'll be re-connecting hosts faster than ever.
On the other hand...
If an ESX host you want to manage doesn't appear in VirtualCenter, you need to add it. This is a bit tricker than reconnecting since there's no inventory in VirtualCenter to tell you the IP addresses of all the hosts you use, and you also need to know a host's password in order to add it. This is another case where entering things in a spreadsheet can really speed things up. I made just such a spreadsheet, and here's a video of me using it.
One big improvement this time around is that we enter the passwords at runtime rather than saving them in the spreadsheet.
As always with these spreadsheets, the script that makes it all work is hidden in cell A2, so if this is not quite what you need you can easily tweak it into something more like what you need.
Also, if you haven't yet downloaded the VI Toolkit (for Windows), there's no reason not to give it a try today.

Quick PowerShell best practice:
Instead of leaving usernames and passwords within a script, you can actually use the built in PowerShell Cmdlet: Get-Credential
Posted by: James Brundage | August 12, 2008 at 11:35 PM
It will prompt if you leave the fields blank, although using read-host since, unfortunately, the API for adding ESX hosts requires a string and can't use a credential.
Posted by: Carter Shanklin | August 13, 2008 at 06:55 AM
Did you hear about VMware FT? I just read a bit about it on http://www.virtualizationteam.com/virtualization-vmware/vmware-esx-40-ft-fault-tolerant-sneak-peek.html
Would u think that would replace VMware HA? I had seen a video even of FT on that link. Is it available yet?
Posted by: andrewstaflin | December 16, 2008 at 01:53 AM
Hi,
we are considering to buy a VMware Virtual Center.
We have two servers running VMware Standard edition.
Do you believe it will be worth it? Or do we have to
upgrade our VMware licenses to Enterprise before upgrading
virtual center to make it worth it. I had just read the
following article
VMware virtual center real value
Posted by: shankyrhodes | January 02, 2009 at 02:42 AM