Change Time Server in Windows devices
- 28 Sep 2023
- 2 Minutes to read
- Print
- PDF
Change Time Server in Windows devices
- Updated on 28 Sep 2023
- 2 Minutes to read
- Print
- PDF
Article summary
Did you find this summary helpful?
Thank you for your feedback
The following Power Shell Script helps the IT Admins to set up a Time Server on their Windows devices. Time Servers help to ensure accurate and synchronized timekeeping across devices on a network as these are critical for compliance, security, troubleshooting, and logging purposes.
- Create a file on your desktop, for example, time_server_windows.ps1 and open it in a text editor like notepad++
- Copy the contents below to the file or click here to download.Shell
# Set the time server $TimeServer = "gbg1.ntp.se" # Configure the time server Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters" ` -Name "NtpServer" -Value $TimeServer Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config" ` -Name "AnnounceFlags" -Value 5 Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient" ` -Name "SpecialPollInterval" -Value 900 Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config" ` -Name "MaxPosPhaseCorrection" -Value 3600 Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config" ` -Name "MaxNegPhaseCorrection" -Value 3600 # Restart the Windows Time service Restart-Service w32time
- This is a PowerShell script that sets the time server on a Windows machine to a defined Time Server and configures some additional settings related to the Windows Time service.
- $TimeServer = "gbg1.ntp.se": This sets the value of $TimeServer to the address of the time server that will be used to synchronize the clock on the Windows machine. Please note that you will need to specify the Time Serverhere as shown in the example.You can find the list of Top Public Time Servers here: https://gist.github.com/mutin-sa/eea1c396b1e610a2da1e5550d94b0453
- Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters" -Name "NtpServer" -Value $TimeServer: This line sets the value of the "NtpServer" registry key to the value of $TimeServer, which configures the time server that the Windows machine will use to synchronize its clock.
- Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config" -Name "AnnounceFlags" -Value 5: This line sets the value of the "AnnounceFlags" registry key to 5, which tells the Windows Time service to announce itself as a reliable time source to other machines on the network.
- Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient" -Name "SpecialPollInterval" -Value 900: This line sets the value of the "SpecialPollInterval" registry key to 900 seconds (15 minutes), which specifies how often the Windows machine should poll the time server for updates.
- Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config" -Name "MaxPosPhaseCorrection" -Value 3600: This line sets the value of the "MaxPosPhaseCorrection" registry key to 3600 seconds (1 hour), which specifies the maximum amount of time that the Windows machine's clock can be adjusted forward.
- Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config" -Name "MaxNegPhaseCorrection" -Value 3600: This line sets the value of the "MaxNegPhaseCorrection" registry key to 3600 seconds (1 hour), which specifies the maximum amount of time that the Windows machine's clock can be adjusted backward.
- Restart-Service w32time: This line restarts the Windows Time service so that the changes take effect.
- $TimeServer = "gbg1.ntp.se": This sets the value of $TimeServer to the address of the time server that will be used to synchronize the clock on the Windows machine. Please note that you will need to specify the Time Serverhere as shown in the example.
- Follow our guide to upload & publish the PowerShell script using Scalefusion Dashboard.
- Once the script is successfully executed, you will be able to see the status of the same in the View Status report on the Scalefusion dashboard.
- Click on the PowerShell script and click on the View Status.
- Executed means that the script has successfully run on the device.
Please note that to use the PowerShell scripts, the Scalefusion MDM Agent Application must be installed on the device(s). Please follow our guide to publish and install the Scalefusion MDM Agent Application.
Notes:
- The scripts and their contents are sourced from various albeit authenticated Microsoft sources and forums.
- Please validate the scripts on a test machine before deploying them on all your managed devices.
- Scalefusion has tested these scripts, however, Scalefusion will not be responsible for any loss of data or system malfunction that may arise due to the incorrect usage of these scripts.
Was this article helpful?