22 # culture="en-US"
33 ConvertFrom-StringData @'
44 NTP = Network Time Protocol
5- WindowsTimeServiceStarted = Windows Time Service Started
5+ NtpSource = NTP source
6+ ServiceStarted = Windows Time service started
67'@
78}
89
@@ -11,24 +12,25 @@ if ($PSUICulture -ne 'en-US') {
1112}
1213
1314function Test ($config ) {
15+ $ruleName = [System.IO.Path ]::GetFileNameWithoutExtension($PSCommandPath )
1416 if ($PSVersionTable.PSEdition -eq ' Core' -and $PSVersionTable.Platform -ne ' Win32NT' ) {
15- $ruleName = [System.IO.Path ]::GetFileNameWithoutExtension($PSCommandPath )
1617 Write-UnsupportedPlatform ($ruleName )
1718 return
1819 }
20+ if (-not (IsLocalAdministrator)) {
21+ Write-RequireAdministrator ($ruleName )
22+ return
23+ }
1924 Write-Output " `n ## $ ( $i18n.NTP ) `n "
2025 # https://learn.microsoft.com/windows-server/networking/windows-time-service/windows-time-service-tools-and-settings
21- $pinfo = New-Object System.Diagnostics.ProcessStartInfo
22- $pinfo.FileName = " w32tm"
23- $pinfo.Arguments = " /query /status"
24- $pinfo.RedirectStandardError = $true
25- $pinfo.RedirectStandardOutput = $true
26- $pinfo.UseShellExecute = $false
27- $p = New-Object System.Diagnostics.Process
28- $p.StartInfo = $pinfo
29- $p.Start () | Out-Null
30- $p.WaitForExit ()
31- $output = $p.StandardOutput.ReadToEnd ().Trim()
32- Write-CheckList ($p.ExitCode -eq 0 ) " $ ( $i18n.WindowsTimeServiceStarted ) "
33- Write-Output " `n`````` log`n $ ( $output ) `n`````` "
26+ $service = Get-Service - Name w32time - ErrorAction SilentlyContinue
27+ Write-CheckList ($service.Status -eq ' Running' ) " $ ( $i18n.ServiceStarted ) "
28+ if ($service.Status -ne ' Running' ) {
29+ Write-CheckList $false " $ ( $i18n.NtpSource ) "
30+ return
31+ }
32+ $source = (& w32tm / query / source | Out-String ).Trim()
33+ Write-CheckList ($source -inotmatch ' (Free-running System Clock|Local CMOS Clock)' ) " $ ( $i18n.NtpSource ) : $ ( $source ) "
34+ $status = (& w32tm / query / status | Out-String ).Trim()
35+ Write-Output " `n`````` log`n $ ( $status ) `n`````` "
3436}
0 commit comments