I installed a vCenter on a VM, and accidentally the IP address of the VM changed (will not lie, I changed intentionally, IP was difficult to rememberJ ). In next few seconds, the hosts that were being managed by vCenter showed as disconnected through vSphere Client. I tried to reconnect them but it displayed “heart beat” mismatch error under “Summary” tab.

There are few steps to rectify this error.

1. From vSphere Client, right-click on the ESX host and click Remove.

2. Remove the agent from ESX host.

3. Add the ESX host again to vCenter inventory. Select New > Add Host.

This will result in reinstallation of the VMware vCenter Server agent.

I tried to automate this in Power Shell. Below is the script for the same:

{code}

$Server = Read-Host "Enter the server name"

$S_User = Read-Host "Enter the User name to connect server"

$S_Password = Read-Host "Enter the Password to connect server"

$DCname = Read-Host "Enter the Datacenter name"

# Connect to server

Connect-VIServer $Server -User $S_User -Password $S_Password

$si = get-view serviceinstance

# Build of the VC

$build = $si.content.about.Build

# Version of the VC

$version = $si.content.about.Version

#Host name to remove the agent

$HostName = Read-Host "Enter the Host name to remove agent"

#Removing the Host from VC

Remove-VMHost -VMHost (Get-VMHost -Name $HostName) -Confirm:$false

$VCBuild = "$version-$build"

#credentials of the User having shell excess

$User = Read-Host "Enter the User name having shell access"

$Password = Read-Host "Enter the User's password having shell access"

#Path of putty available

$plink = "c:\putty\plink.exe"

$plinkoptions = " -v -batch -pw $Password"

#To implement special commands like "|" and "&&" ,I have used the below way

$cmd1 = 'rpm -qa "|" grep vpxa'

$cmd2 = 'service mgmt-vmware stop "&&" service vmware-vpxa stop "&&" service vmware-vmkauthd stop "&&" service xinetd restart'

$cmd3 = 'rpm -qa "|" grep -i vpxa "|" awk ''{print $1}''"|" xargs rpm -ef $1 "&&" userdel vpxuser "&&" service mgmt-vmware start "&&" service vmware-vmkauthd start'

#command1 for VirtualCenter Agents on Host

$command = $plink + " " + $plinkoptions + " " + $User + "@" + $HostName + " " + $cmd1

#command2 for stopping the management services

$command2 = $plink + " " + $plinkoptions + " " + $User + "@" + $HostName + " " + $cmd2

#command3 for removing the vpxa agent, "userdel vpxuser" removes the vpxa user, restart the services of Host

$command3 = $plink + " " + $plinkoptions + " " + $User + "@" + $HostName + " " + $cmd3

#invoking the command1

$msg = Invoke-Expression -command $command

#invoking the command2

$msg1 = Invoke-Expression -command $command2

#invoking the command3

$msg2 = Invoke-Expression -command $command3

#time given to restart the services

sleep -Seconds 500

# Adding the Host to the VC, agent will automatically get installed

Add-VMHost -Name $HostName -User $User -Password $Password -Location (Get-Datacenter -Name $DCname)

{code}

Pre-requisites to run the above script:-

  1. PowerShell
  2. VMware vSphere PowerCLI
  3. Putty

Note: This script will work against ESX classic hosts only.

2 comments:

  1. Unknown said...

    Very informative I've found your blog via Google and I'm really happy about the information you provide

    Proxy Server

  2. Unknown said...

    So I used some of this code, and for that I am grateful. For those that do not want to disconnect, and reconnect their hosts, and have to change their vcenter IP, and ESX IP addresses I have a script (WIP) that will enable SSH through PowerCLI, and edit the vpxa.cfg file through plink / grep | sed, and restart the vpxa mgmt service. Message me if interested.



Copyright 2009 InterraIT template by Blogcrowds.