VMware Cloud Community
ChrisRayDekraSE
Contributor
Contributor
Jump to solution

VMware ESXi Host Time Configuration - Refresh / Last Sync Time

Is there a way to refresh the time service synchronization status via PowerCLI? Essentially I'm looking for a way to programmatically press the "Refresh" button in the attached screenshot.

I'd also like to know if its possible to access the "Last time sync" and current source of time via PowerCLI?

It would appear that in VMware ESXi 7.0.3 Build 20328353 this "Time service is current not synchronized" warning is a false positive. Hitting the refresh button does appear to clear the warning, but I'm not sure how long for as I only spotted this issue this morning.

The time on the VMware ESXi host is correct (verified via an SSH connection to the host and used the date command to show the current time). The host is also communicating with the NTP servers without any problems (ntpq -p shows 377 in the reach column for both NTP servers).

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Not via a cmdlet, but you can use the RefreshDateTimeSystem method.

$esxName = 'MyEsx'

$esx = Get-VMHost -Name $esxName
$timeSys = Get-View -Id $esx.ExtensionData.ConfigManager.DateTimeSystem
$timeSys.RefreshDateTimeSystem()


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
3 Replies
ChrisRayDekraSE
Contributor
Contributor
Jump to solution

It looks like this might expose some of the properties but as far as I can see there is no "refresh" method:

Before - Refresh in vSphere Client:

$VMHost = Get-VMHost <ESXI Hostname>
$View = Get-View $VMHost.ExtensionData.ConfigManager.DateTimeSystem
$View.DateTimeInfo

TimeZone            : VMware.Vim.HostDateTimeSystemTimeZone
SystemClockProtocol : ntp
NtpConfig           : VMware.Vim.HostNtpConfig
PtpConfig           : VMware.Vim.HostPtpConfig
Enabled             : True
DisableEvents       : False
DisableFallback     : True
InFallbackState     : False
ServiceSync         : False
LastSyncTime        :
RemoteNtpServer     :
NtpRunTime          : 38
PtpRunTime          :
NtpDuration         : less than a minute
PtpDuration         :


After - Refresh in vSphere Client:

$VMHost = Get-VMHost <ESXi Hostname>
$View = Get-View $VMHost.ExtensionData.ConfigManager.DateTimeSystem
$View.DateTimeInfo

TimeZone            : VMware.Vim.HostDateTimeSystemTimeZone
SystemClockProtocol : ntp
NtpConfig           : VMware.Vim.HostNtpConfig
PtpConfig           : VMware.Vim.HostPtpConfig
Enabled             : True
DisableEvents       : False
DisableFallback     : True
InFallbackState     : False
ServiceSync         : True
LastSyncTime        : 09/02/2023 03:37:03
RemoteNtpServer     : 10.###.###.### stratum: 3
NtpRunTime          : 2941763
PtpRunTime          :
NtpDuration         : less than a month
PtpDuration         :

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not via a cmdlet, but you can use the RefreshDateTimeSystem method.

$esxName = 'MyEsx'

$esx = Get-VMHost -Name $esxName
$timeSys = Get-View -Id $esx.ExtensionData.ConfigManager.DateTimeSystem
$timeSys.RefreshDateTimeSystem()


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ChrisRayDekraSE
Contributor
Contributor
Jump to solution

Thanks LucD! That worked perfectly! 🙂

Reply
0 Kudos