2

I've been trying to do an audit of time skews on some of my hosts recently. Using PowerCLI I found a few scripts that reference the ConfigManager.DateTimeSystem to get the ESXi Host datetime. However A few hosts seem to have 2 time entries/2 HostDateTimeSystem properties. Sometimes they are the same, sometimes they are different.

The hosts are all ESXi 5.5.

Using: Get-View -ViewType HostSystem -Property Name,ConfigManager.DateTimeSystem | sort Name | select Name,@{Name="Current VMHostTime";Expression={(Get-View $_.ConfigManager.DateTimeSystem)}}

Current VMHost Time

7/9/2014 3:55:20 PM

{7/9/2014 3:40:57 PM, 7/9/2014 3:55:20 PM}   <------  Two entries at different times

7/9/2014 3:55:20 PM

7/9/2014 3:55:20 PM

7/9/2014 3:55:20 PM

7/9/2014 3:55:20 PM

{7/9/2014 3:55:20 PM, 7/9/2014 3:42:07 PM}

7/9/2014 3:55:20 PM

7/9/2014 3:55:20 PM

7/9/2014 3:43:16 PM

7/9/2014 3:40:39 PM

7/9/2014 3:41:26 PM

{7/9/2014 3:42:07 PM, 7/9/2014 3:55:20 PM}

7/9/2014 3:43:29 PM

7/9/2014 3:42:37 PM

7/9/2014 3:41:43 PM

7/9/2014 3:42:43 PM

7/9/2014 3:41:25 PM

{7/9/2014 3:40:58 PM, 7/9/2014 3:55:21 PM}

Dropping out the actual date formatting I see the following:

Current VMHost Time

VMware.Vim.HostDateTimeSystem

{VMware.Vim.HostDateTimeSystem, VMware.Vim.HostDateTimeSystem}   <--- Two entries for the host time???

VMware.Vim.HostDateTimeSystem

VMware.Vim.HostDateTimeSystem

VMware.Vim.HostDateTimeSystem

VMware.Vim.HostDateTimeSystem

{VMware.Vim.HostDateTimeSystem, VMware.Vim.HostDateTimeSystem}

VMware.Vim.HostDateTimeSystem

VMware.Vim.HostDateTimeSystem

VMware.Vim.HostDateTimeSystem

VMware.Vim.HostDateTimeSystem

VMware.Vim.HostDateTimeSystem

{VMware.Vim.HostDateTimeSystem, VMware.Vim.HostDateTimeSystem}

VMware.Vim.HostDateTimeSystem

VMware.Vim.HostDateTimeSystem

VMware.Vim.HostDateTimeSystem

VMware.Vim.HostDateTimeSystem

VMware.Vim.HostDateTimeSystem

{VMware.Vim.HostDateTimeSystem, VMware.Vim.HostDateTimeSystem}

Does anyone have any idea why/how a hand full of hosts have 2 time entries? Can this be corrected so we can be certain that the hosts are set to a single definitive time?

  • Can you post the code you used to get the timestamps from "VMware.Vim.HOstDateTimeSystem"? thanks, – Lars Aug 19 '14 at 15:10
0

I was unable to find any ESXi hosts displaying multiple dates. Could you post your entire script?

Below is a PowerCLI script to show time skew between workstation, vcenter, and ESXi hosts. I am curious to see the output against your hosts with multiple timestamps:

Clear-Host
$ErrorActionPreference = "Continue"
$DebugPreference = "SilentlyContinue"
$VerbosePreference = "SilentlyContinue"

@"
## get_TIMEDRIFT.ps1 ##########################################################
Usage:        powershell -ExecutionPolicy Bypass -File ./get_TIMEDRIFT.ps1

Version:      1.0 (20140915)

Purpose:      Quickly Display time-drift between Workstation, vCenter, and ESXi
              hosts.  For the purpose of finding ESXi hosts which can cause
              issues if VMs are set to sync time through VMware Tools.
              vCAC/IAAS servers will not work propertly if not in sync with SSO

Requirements: Windows Powershell and running on machine with VI Tools/powercli

History:      09/15/2014  -  Created

###############################################################################
"@

## Virtual Center Server to test for time-drift against.
$VCServer = "VCEN.TEST.LOCAL"

## If running PS1 script from Powershell instead of PowerCLI, load vcen snap-in
$SIval = Get-PSSnapin -Name VMware.VimAutomation.Core `
                      -ErrorAction SilentlyContinue
if (($SIval) -eq $null) { Add-PSSnapin VMware.VimAutomation.Core }

## Logon to vCenter Server, will prompt for name/password if not saved.
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore `
                          -Scope Session `
                          -Confirm:$false
$VC = Connect-VIServer $VCServer
Write-Output "Connected to '$($VC.Name):$($VC.port)' as '$($VC.User)'"

## Get vCenter and LocalSystem timestamps and drift
    # get LocalSystem time
    $_localtime = Get-Date
    $_localtimeUTC = $_localtime.ToUniversalTime()
    # get vCenter time
    $_vctime = $VC.ExtensionData.ServerClock
    $_vctimeUTC = $_vctime.ToUniversalTime() 
    # determine time drift between LocalSystem and vCenter
    $_localdrift = ($_localtimeUTC - $_vctimeUTC).duration()


## Loop through ESX hosts writing output for each
$vmhosts = Get-VMHost
foreach($esx in $vmhosts){
    $esxview = Get-View -viewtype "HostSystem" -Filter @{"Name" = $esx.Name}
    $esxdatetimesystem = $esxview.configmanager.datetimesystem
    $_remote = Get-View -Id $esxdatetimesystem
    $_remotetime = $_remote.QueryDateTime()
    $_remotetimeUTC = $_remotetime.ToUniversalTime()
    $_vctime = $VC.ExtensionData.ServerClock
    $_vctimeUTC = $_vctime.ToUniversalTime()
    $_remotedrift = ($_remotetimeUTC - $_vctimeUTC).duration()
    Write-Output "  $esx Time drift from vCenter in minutes:: '$($_remotedrift.Totalminutes)'"
    }

## Ouput timestamps for Local Workstation, and vCenter Server
Write-Output "  vCenter Server UTC:: $_vctime"
Write-Output "  Workstation (Actual | UTC):: $_localtime | $_localtimeUTC"
Write-Output "  Local workstation Time drift from vCenter in minutes:: '$($_localdrift.Totalminutes)'"

## Disconnect user from vCenter Server
Write-Output "Disconnecting '$($VC.User)' from '$($VC.Name):$($VC.port)'"
Disconnect-VIServer $VC -Confirm:$false

Sample Output below:

Connected to 'VCEN.TEST.LOCAL:443' as 'TEST\FMLast'
  192.168.15.149 Time drift from vCenter in minutes:: '10280.9866862833'
  192.168.15.159 Time drift from vCenter in minutes:: '10281.0125832833'
  192.168.15.167 Time drift from vCenter in minutes:: '10281.0392954333'
  192.168.15.168 Time drift from vCenter in minutes:: '10281.0690222667'
  192.168.15.26 Time drift from vCenter in minutes:: '10281.0986537667'
  192.168.15.24 Time drift from vCenter in minutes:: '10281.1276888833'
  192.168.15.25 Time drift from vCenter in minutes:: '10281.1569679333'
  192.168.15.22 Time drift from vCenter in minutes:: '10281.1863135333'
  192.168.15.27 Time drift from vCenter in minutes:: '10281.2183166667'
  192.168.15.23 Time drift from vCenter in minutes:: '10281.246763'
  vCenter Server UTC:: 09/08/2014 16:38:04
  Workstation (Actual | UTC):: 09/15/2014 15:59:01 | 09/15/2014 19:59:01
  Local workstation Time drift from vCenter in minutes:: '10280.9408839317'
Disconnecting 'TEST\FMLast' from 'VCEN.TEST.LOCAL:443'
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.