Skip to content
Franck SALLET edited this page Sep 5, 2026 · 1 revision

NTP

Windows Time service (w32tm) configuration, peer status, sync status, and resync actions.

5 function(s) in Public/ntp/.

Functions

  • Get-NTPConfiguration — Retrieves the current Windows Time Service (W32Time) NTP configuration and status
  • Get-NTPPeer — Retrieves NTP peer information from the Windows Time service
  • Get-NTPSyncStatus — Retrieves NTP synchronization status on Windows machines
  • Set-NTPClient — Configures Windows Time Service (W32Time) to synchronize with specified NTP servers
  • Sync-NTPTime — Forces NTP time resynchronization on Windows machines

Reference

Get-NTPConfiguration

Retrieves the current Windows Time Service (W32Time) NTP configuration and status.

This function queries the Windows Time Service using w32tm commands to retrieve the complete NTP configuration, including configured servers, poll intervals, synchronization status, peer details, and last successful sync time.

Supports both local and remote computers. Remote queries use WinRM (Invoke-Command). For bulk queries, errors per computer are non-terminating to allow the pipeline to continue processing remaining computers.

Returns a structured PSCustomObject with all relevant NTP configuration data for easy consumption by other scripts or for display purposes.

Syntax

Get-NTPConfiguration [-ComputerName <string[]>] [-IncludePeerDetails]

Examples

Get-NTPConfiguration

Retrieves the current NTP configuration for the local computer.

Get-NTPConfiguration -ComputerName 'SRV01', 'SRV02'

Retrieves NTP configuration for two remote servers.

'SRV01', 'SRV02' | Get-NTPConfiguration

Pipeline usage: queries NTP configuration on both servers.

Get-NTPConfiguration -Verbose | Format-List

Retrieves NTP configuration with verbose logging and displays all properties as a list.

$ntpConfig = Get-NTPConfiguration -IncludePeerDetails
$ntpConfig.ConfiguredServers
$ntpConfig.PeerDetails

Retrieves configuration with peer details and accesses specific properties.

Output: PSWinOps.NtpConfiguration

NTP client configuration including source, type, and poll intervals.


Get-NTPPeer

Retrieves NTP peer information from the Windows Time service.

Parses the output of 'w32tm /query /peers' to return structured NTP peer objects. Supports both modern and legacy w32tm output formats, including French-locale output. Uses block-based parsing: raw output is split on blank lines, the header block is skipped, and each subsequent block is parsed as one peer entry.

Note: LastSyncTime is not available from /query /peers. Use Get-NTPConfiguration (which queries /query /status) for last synchronization information.

Syntax

Get-NTPPeer [-ComputerName <string[]>]

Examples

Get-NTPPeer
Returns NTP peer information for the local computer.
Get-NTPPeer -ComputerName 'SRV01', 'SRV02'
Returns NTP peer information for two remote servers.
'SRV01', 'SRV02' | Get-NTPPeer
Pipeline usage: queries NTP peers on both servers.

Output: PSWinOps.NtpPeer

NTP peer status including stratum, delay, and offset.


Get-NTPSyncStatus

Retrieves NTP synchronization status on Windows machines.

Queries the Windows Time Service (w32tm) to retrieve NTP synchronization details on one or more machines. Parses the output of 'w32tm /query /status' to extract source, stratum, phase offset, last sync time, leap indicator, and poll interval.

Supports both English and French locale w32tm output via locale-agnostic regex patterns. Uses direct w32tm calls for local queries and Invoke-Command for remote execution, avoiding unnecessary serialization overhead on the local machine.

Syntax

Get-NTPSyncStatus [-ComputerName <string[]>] [-MaxOffsetMs <int>]

Examples

Get-NTPSyncStatus

Retrieves NTP sync status on the local machine with the default 1000ms threshold.

Get-NTPSyncStatus -ComputerName 'DC01' -MaxOffsetMs 500

Retrieves NTP sync status on remote server DC01 with a 500ms offset threshold.

'DC01', 'DC02', 'WEB01' | Get-NTPSyncStatus -MaxOffsetMs 2000

Pipeline example: retrieves NTP sync status on multiple machines with a 2-second threshold.

Output: PSWinOps.NtpSyncResult

NTP synchronization status with offset and compliance flag.


Set-NTPClient

Configures Windows Time Service (W32Time) to synchronize with specified NTP servers.

This function configures the Windows Time Service (W32Time) to use external NTP servers for time synchronization. It sets the NTP server list, phase offset tolerance, and polling intervals via registry and w32tm commands. The function ensures the service is running, applies the configuration, restarts the service, forces synchronization, and verifies the final state.

Requires local administrator privileges to modify registry and manage the W32Time service.

Syntax

Set-NTPClient -NtpServers <string[]> [-MaxPhaseOffset <int>] [-SpecialPollInterval <int>] [-MinPollInterval <int>] [-MaxPollInterval <int>]

Examples

Set-NTPClient -NtpServers 'time.windows.com', 'pool.ntp.org'
Configures W32Time with two public NTP servers using default poll settings.
Set-NTPClient -NtpServers 'time.windows.com', 'pool.ntp.org' -MaxPhaseOffset 5 -Verbose
Configures W32Time with custom NTP servers and a 5-second phase offset tolerance,
with verbose logging enabled.
Set-NTPClient -NtpServers 'ntp.example.com' -SpecialPollInterval 600 -MinPollInterval 7 -MaxPollInterval 12 -WhatIf
Shows what would happen if the configuration were applied with custom poll intervals.

Sync-NTPTime

Forces NTP time resynchronization on Windows machines.

Forces a resynchronization of the Windows Time Service (w32tm) on one or more local or remote machines. Optionally restarts the Windows Time service before resyncing to ensure a clean state. Uses the w32tm exit code (locale-agnostic) to determine success or failure per machine.

Uses direct w32tm calls for local execution (mockable in Pester) and Invoke-Command for remote targets, matching the pattern used by all NTP functions. Each machine is processed independently with per-machine error isolation -- a failure on one target does not prevent processing of subsequent targets.

Supports -WhatIf and -Confirm via SupportsShouldProcess. Since ConfirmImpact is Medium and the default ConfirmPreference is High, the function does not prompt by default. Pass -Confirm to force a prompt, or -Confirm:$false to suppress it explicitly in automation contexts.

Syntax

Sync-NTPTime [-ComputerName <string[]>] [-RestartService]

Examples

Sync-NTPTime

Forces an NTP resync on the local machine using default parameters.

Sync-NTPTime -ComputerName 'SRV-DC01'

Forces an NTP resync on a single remote machine.

Sync-NTPTime -ComputerName 'SRV-DC01', 'SRV-DC02' -RestartService -Verbose

Restarts the w32time service then forces an NTP resync on two remote machines, with verbose logging enabled.

Get-Content -Path 'C:\Admin\servers.txt' | Sync-NTPTime -RestartService

Reads a list of server names from a file and pipelines them into Sync-NTPTime, restarting the w32time service on each before resyncing.

Output: PSWinOps.NtpResyncResult

Resynchronization result with status and any error details.


PSWinOps Wiki

Home

Domains

Clone this wiki locally