Adding a Host to vCenter Fails Because of Time Issues

I recently experienced an issue adding a vSphere 5.1 host to vCenter while using the Add-VMHost cmdlet in PowerCLI. I’m pretty sure the same problem would have occured if I was using the GUI, but this work was for part of some automated deployment work.

On a freshly baked ESXi 5.1 install one of the first tasks is to get it into vCenter. However, this was failing with what initially appeared to be a license issue, despite there being plenty of available licenses.

“The Evaluation Mode license assigned to Host xxxx.xxxx.xxxx has expired. Recommend updating the license.”

 

 

Turns out the issue was related to the date and time being incorrect on the host (it had been powered off for some time) and consequently the eval license had ’expired’ even though it has just been installed.

http://kb.vmware.com/kb/2011655

Despite the fact that my automated deployment configures NTP settings and starts the NTP service before adding the host to vCenter, the host had not yet corrected to the current date and time - possibly because it was so far out, in this case more than 1 year.

So to ensure the date and time are correct before adding the host to vCenter, I created the Set-VMHostToCurrentDateandTime function below. This uses the UpdateDateTime method to set the time on the ESXi host to the current time. I recommend you configure NTP settings and start the NTP service, then carry out the time set. You can use it in the following manner:


Get-VMHost ESXi01| Set-VMHostToCurrentDateandTime

 


function Set-VMHostToCurrentDateandTime { <# .SYNOPSIS Function to set the Date and Time of a VMHost to current.

.DESCRIPTION Function to set the Date and Time of a VMHost to current.

.PARAMETER VMHost VMHost to configure Date and Time settings for.

.INPUTS String. System.Management.Automation.PSObject.

.OUTPUTS None.

.EXAMPLE PS> Set-VMHostToCurrentDateandTime -VMHost ESXi01

.EXAMPLE PS> Get-VMHost ESXi01,ESXi02 | Set-VMHostToCurrentDateandTime

#> \[CmdletBinding()\]

Param (

\[parameter(Mandatory=$true,ValueFromPipeline=$true)\] \[ValidateNotNullOrEmpty()\] \[PSObject\[\]\]$VMHost )

begin {

}

process {

foreach ($ESXiHost in $VMHost){

try {

if ($ESXiHost.GetType().Name -eq "string"){

try { $ESXiHost = Get-VMHost $ESXiHost -ErrorAction Stop } catch \[Exception\]{ Write-Warning "VMHost $ESXiHost does not exist" } }

elseif ($ESXiHost -isnot \[VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl\]){ Write-Warning "You did not pass a string or a VMHost object" Return }

\# --- Set the Date and Time to the current Date and Time Write-Verbose "Setting the Date and Time to the current Date and Time for $ESXiHost" $Time = Get-Date $DateTimeSystem = $ESXiHost | ForEach-Object { Get-View $\_.ExtensionData.ConfigManager.DateTimeSystem } $DateTimeSystem.UpdateDateTime((Get-Date($Time.ToUniversalTime()) -Format u)) Write-Verbose "Successfully set the Date and Time to the current Date and Time for $ESXiHost" } catch \[Exception\]{

throw "Unable to set current Date and Time" } } } end {

} }

Thanks to this post for refreshing my memory on how to do this