Last active
September 29, 2022 03:55
-
-
Save takato3000/33dcbcd4404d7d25ea44f082cf4d5ba5 to your computer and use it in GitHub Desktop.
windows ntp powershell script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Set-TimeSynchronization { | |
| param( | |
| [string[]] $TimeSource = 'time.windows.com', | |
| [int] $MaxPosPhaseCorrection = 5, | |
| [int] $MaxnegPhaseCorrection = 5, | |
| [int] $PollInterval = 1800 | |
| ) | |
| ## set external time source | |
| ## set server type to NTP | |
| Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters -Name Type -Value 'NTP' | |
| Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config -Name AnnounceFlags -Value 5 | |
| ## Enable NTP server | |
| Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer -Name Enabled -Value 1 | |
| ## Specify Time source | |
| Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters -Name NtpServer -Value "$TimeSource,0x1" | |
| ## Set poll interval in seconds - every 30 minutes | |
| Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient -Name SpecialPollInterval -Value $PollInterval | |
| ## set max +/- time corrections in seconds - 5 seconds | |
| Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config -Name MaxPosPhaseCorrection -Value $MaxPosPhaseCorrection | |
| Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config -Name MaxnegPhaseCorrection -Value $MaxnegPhaseCorrection | |
| Stop-Service -Name W32Time | |
| Start-Service -Name W32Time | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment