-
Notifications
You must be signed in to change notification settings - Fork 1
/
NTP.psm1
36 lines (34 loc) · 1.32 KB
/
NTP.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$i18n = Data {
# culture="en-US"
ConvertFrom-StringData @'
NTP = Network Time Protocol
NtpSource = NTP source
ServiceStarted = Windows Time service started
'@
}
if ($PSUICulture -ne 'en-US') {
Import-LocalizedData -BindingVariable i18n
}
function Test($config) {
$ruleName = [System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath)
if ($PSVersionTable.PSEdition -eq 'Core' -and $PSVersionTable.Platform -ne 'Win32NT') {
Write-UnsupportedPlatform($ruleName)
return
}
if (-not (IsLocalAdministrator)) {
Write-RequireAdministrator($ruleName)
return
}
Write-Output "`n## $($i18n.NTP)`n"
# https://learn.microsoft.com/windows-server/networking/windows-time-service/windows-time-service-tools-and-settings
$service = Get-Service -Name w32time -ErrorAction SilentlyContinue
Write-CheckList ($service.Status -eq 'Running') "$($i18n.ServiceStarted)"
if ($service.Status -ne 'Running') {
Write-CheckList $false "$($i18n.NtpSource)"
return
}
$source = (& w32tm /query /source | Out-String).Trim()
Write-CheckList ($source -inotmatch '(Free-running System Clock|Local CMOS Clock)') "$($i18n.NtpSource): $($source)"
$status = (& w32tm /query /status | Out-String).Trim()
Write-Output "`n``````log`n$($status)`n``````"
}