-
Notifications
You must be signed in to change notification settings - Fork 1
/
32.Set-NtpServer.ps1
60 lines (57 loc) · 1.92 KB
/
32.Set-NtpServer.ps1
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<#
.Synopsis
Sets the NTP server on PDC emulation role
.DESCRIPTION
Sets the NTP server on PDC emulation role
.EXAMPLE
.\Set-NtpServer.ps1
.EXAMPLE
Set-NtpServer.ps1 -NtpServer "172.17.69.122,0x8 10.243.24.108,0x8"
.NOTES
General notes
#>
[CmdletBinding(SupportsShouldProcess=$true)]
Param
(
# Param1 help description
[Parameter(Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[string[]]$NtpServer=@("172.17.69.122","10.243.24.108")
)
Begin
{
[string[]]$NtpServerList=$NtpServer | % { "$_,0x8" }
[string]$NtpServers = $NtpServerList -join " "
$NtpServers
}
Process
{
$DomainRole = (Get-WmiObject -Class Win32_ComputerSystem).DomainRole
Switch ($DomainRole) {
5 { # PDC emulator role on local machine. But: is it also DC in the forest root?
if ((Get-ADDomain).DNSRoot -eq (Get-ADForest).Name) {
if ($pscmdlet.ShouldProcess("PDC", "Update Sync to NTP server")) {
W32TM /Config /Manualpeerlist:$NtpServers /SyncFromFlags:Manual /Reliable:Yes /Update
}
} else {
if ($pscmdlet.ShouldProcess("PDC", "Update Sync to Domain hierarchy")) {
W32TM /Config /SyncFromFlags:DOMHIER /Reliable:No /Update
}
}
}
Default {
if ($pscmdlet.ShouldProcess("Non-PDC", "Update Sync to Domain hierarchy")) {
W32TM /Config /SyncFromFlags:DOMHIER /Reliable:No /Update
}
}
}
}
End
{
W32TM /Query /Source
W32TM /Query /Configuration
}