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)
« Previous Next »

Part of the series

  1. PowerShell Module for Time Synchronization - Get current time in UTC from internet
  2. PowerShell Module for Time Synchronization - PowerShell Workflow to get status and current configuration of Time Sync from remote servers in parallel
  3. PowerShell Module for Time Synchronization - PowerShell Workflow to start (invoke) Time Sync on remote servers in parallel
  4. PowerShell Module for Time Synchronization - PowerShell Workflow to wait for Time Sync and automatically correct (repair) Time Sync on remote servers in parallel
  5. PowerShell Module for Time Synchronization - PowerShell Workflow for testing and monitoring of Time Sync on remote servers in parallel