PowerShell Module for Time Synchronization – PowerShell Workflows to get status, start, invoke, test, monitor and repair Time Sync


I decided to write PowerShell module to deal with Time Synchronization.

I wrote following PowerShell Workflows:

  • Get-VDateTimeInternetUtc
    • Very simple Workflow to get current date and time in UTC (Coordinated Universal Time) from the internet.
    • The date and time is obtained from public website over HTTP (TCP 80) so it is possible to use this workflow in environments without direct access to internet (for example over proxy).
    • It is PowerShell Workflow so this script could be for example used via Service Management Automation (SMA) on Microsoft Azure
  • Get-VSystemTimeSynchronization
    • Get information from the local server or from multiple remote servers in parallel.
    • This is the most important part of the module. Most of the logic is done via this Workflow.
    • Get current configuration of Time Synchronization.
      • Script will trigger following paths in Windows Registry to get current time sources (configured NTP servers)
        • HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\W32Time\Parameters
        • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters
    • Get current time source. That means get current NTP server, get information that NTP server is not used (internal clock only) or for example get information that synchronization is done on Hyper-V Time Synchronization service.
    • Get date and time of the last time synchronization.
    • Return error when last time synchronization was done a long time ago (more than specified number of seconds).
    • Return error when the current time source is not within NTP servers specified in Windows Registry.
    • Return error when the current time source is or is not within specified types of time sources.
  • Start-VSystemTimeSynchronization
    • Start time synchronization on the local server or invoke time synchronization on multiple remote servers in parallel.
    • Start immediate time synchronization or re-discover time sources.
  • Wait-VSystemTimeSynchronization
    • Wait for time synchronization on the local server or invoke operations on multiple remote servers in parallel.
    • Wait for an infinitely long or do only specified number or repetitions and trials to get correct status of time synchronization.
    • Correct (repair) current state of time synchronization.
      • Trigger rediscover of time source when the current time source is not within the specified NTP servers or the specified type of time source.
      • Trigger immediate time synchronization when the last time synchronization was done a long time ago (more than specified number of seconds).
  • Test-VSystemTimeSynchronization
    • Test current state of time synchronization on the local server or on multiple remote servers in parallel.
    • Orchestrate regular monitoring of the time synchronization on multiple remote servers in parallel.
    • Compare time difference between remote server and specified NTP server (it is a good idea to use different NTP server then then NTP server that is used internally)
      • UDP 123 communication between remote server and specified NTP server
      • Accurate but firewall opening is required
    • Compare time difference between remote server and time on the internet.
      • TCP 80 (HTTP) from the server that orchestrate monitoring to internet
      • Not accurate but firewall opening is not required (monitoring server may have access to the internet or could be done via proxy)

One response to “PowerShell Module for Time Synchronization – PowerShell Workflows to get status, start, invoke, test, monitor and repair Time Sync”

  1. Hi Rudolf, I am trying to test this in my environment and i started with Get-VSystemTimeSynchronization module. When i run this script, i am getting below shown error, I have no experience with Powershell, please help me to get it work [You must provide a value expression on the right-hand side of the ‘-‘ operator. At C:\temp\Get-VSystemTimeSynchronization.ps1:601 char:12 <<<< PSComputerName $ComputerName `

Leave a Reply

Your email address will not be published. Required fields are marked *

Active Directory Advanced function AlwaysOn Availability Groups AlwaysOn Failover Cluster Instances Building Cloud Cloud Cluster Cmdlet Database Deployment Design DFS Domain Controller DSC Fabric Failover Clustering File Server Group Policy Hardware Profile Host Hyper-V Installation Library Library Asset Library Server Network Operations Manager Orchestrator PowerShell PowerShell User Group PowerShell Workflow Security Service Manager SQL Server Storage System Center Template Time Time Synchronization Tips Virtual Machine Virtual Machine Manager VM Network VM Template Windows Server 2012 R2