Skip to content

Instantly share code, notes, and snippets.

@d4rkeagle65
Created January 7, 2022 15:02
Show Gist options
  • Save d4rkeagle65/4574ceb635b6478eedb9e530615001d2 to your computer and use it in GitHub Desktop.
Save d4rkeagle65/4574ceb635b6478eedb9e530615001d2 to your computer and use it in GitHub Desktop.
Enables Windows Server to server NTP to clients on a network and configures the upstream time server to time.windows.com. Also creates a firewall rule to allows incoming connections to UDP port 123 for NTP clients.
Set-TimeZone -Name 'Eastern Standard Time'
Set-Service -Name W32Time -StartupType Automatic
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer' -Name 'Enabled' -Value 1 -Force
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config' -Name 'AnnounceFlags' -Value 0xA -Force
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient' -Name 'Enabled' -Value 1 -Force
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient' -Name 'SpecialPollInterval' -Value 300 -Force
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters' -Name 'Type' -Value 'NTP' -Force
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters' -Name 'NtpServer' -Value 'time.windows.com,0x8' -Force
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config' -Name 'MaxPosPhaseCorrection' -Value 1800 -Force
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config' -Name 'MaxNegPhaseCorrection' -Value 1800 -Force
New-NetFirewallRule `
-Name "NTP Server Port" `
-DisplayName "NTP Server Port" `
-Description 'Allow NTP Server Port' `
-Profile Any `
-Direction Inbound `
-Action Allow `
-Protocol UDP `
-Program Any `
-LocalAddress Any `
-LocalPort 123
Restart-Service -Name W32Time -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment