Hasleo Software Forums

Full Version: How can I ensure the system time is always correct on every boot?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The VHDX (Windows 11) is running from a USB-connected NVMe enclosure.

Every time I start the system, the system time is always incorrect and does not update automatically unless I manually toggle "Set time automatically" in the Date and Time settings after each boot.

Is there a way to ensure the system time is set correctly at boot (ideally syncing automatically), without needing to manually adjust this setting every session?
I should also note that the network connection takes some time to establish on boot (about 30 seonds).
Do you mean that the “Set time automatically” setting cannot be saved permanently? There is nothing we can do about the network connection.
(07-22-2025, 11:27 PM)admin Wrote: [ -> ]Do you mean that the “Set time automatically” setting cannot be saved permanently? There is nothing we can do about the network connection.

I can toggle it and set it and its working fine. However upon every reboot the time is always wrong. So if it toggle it again it fixes it to the correct time. In regards to the network connection thats not an issue, I mentioned that for extra information in case that was a contriubting factor.
It doesn't automatically synchronize the time when the internet connection is stable?
(07-22-2025, 11:55 PM)admin Wrote: [ -> ]It doesn't automatically synchronize the time when the internet connection is stable?

No, it doesn’t auto sync for some reason. I’ve put together a PowerShell script with a 2-minute delayed startup (to give the network enough time to come online) to handle the sync.

PHP Code:
# Sync-WindowsTime.ps1

# Self-elevation block: Relaunch with admin rights if necessary
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()
    ).
IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
    
Write-Host "Relaunching PowerShell as Administrator..."
    
$params "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""
    Start-Process powershell.exe -Verb RunAs -ArgumentList 
$params
    exit
}

# Check the status of Windows Time service
$service = Get-Service -Name w32time -ErrorAction SilentlyContinue

if (
$null -eq $service) {
    Write-Host "Windows Time service (w32time) not found."
    exit 1
}

if (
$service.Status -ne 'Running') {
    Write-Host "Windows Time service is not running. Starting the service..."
    Start-Service -Name w32time
    Start-Sleep -Seconds 2
} else {
    Write-Host "Windows Time service is already running."
}

# Force time sync
Write-Host "Forcing time synchronization..."
w32tm /resync /force

Write-Host "Time synchronization command executed."
Start-Sleep -Seconds 2
exit 
(07-29-2025, 06:36 AM)bacevs Wrote: [ -> ]
(07-22-2025, 11:55 PM)admin Wrote: [ -> ]It doesn't automatically synchronize the time when the internet connection is stable?

No, it doesn’t auto sync for some reason. I’ve put together a PowerShell script with a 2-minute delayed startup (to give the network enough time to come online) to handle the sync.

PHP Code:
# Sync-WindowsTime.ps1

# Self-elevation block: Relaunch with admin rights if necessary
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()
    ).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
    Write-Host "Relaunching PowerShell as Administrator..."
    $params "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""
    Start-Process powershell.exe -Verb RunAs -ArgumentList 
$params
    exit
}

# Check the status of Windows Time service
$service = Get-Service -Name w32time -ErrorAction SilentlyContinue

if (
$null -eq $service) {
    Write-Host "Windows Time service (w32time) not found."
    exit 1
}

if (
$service.Status -ne 'Running') {
    Write-Host "Windows Time service is not running. Starting the service..."
    Start-Service -Name w32time
    Start-Sleep -Seconds 2
} else {
    Write-Host "Windows Time service is already running."
}

# Force time sync
Write-Host "Forcing time synchronization..."
w32tm /resync /force

Write-Host "Time synchronization command executed."
Start-Sleep -Seconds 2
exit 

This seems like a very good solution. Thank you for sharing.