PowerShell 通过NTP/NT5DS同步时间
2011-11-02 09:41
501 查看
PowerShell通过NTP/NT5DS同步时间.
############################################################################ ##SyncTime.ps1 ##Client time synchronization ##Set the time from ntp server ##If the computer is in domain,using NT5DS to synchronize the time to domain hierarchy.Else using NTP to synchronize the time to the server time.windows.com ##Hsing Hsu ##meng-xing.xu@hp.com ##2011.11.1 ############################################################################ param($type,$help) function funHelp() { $helpText=@" DESCRIPTION: NAME:SyncTime.ps1 Synchronize the client time. PARAMETERS: -type The type <NTP/NT5DS> of synchronizing the time. -help print help file SYNTAX: SyncTime.ps1 Generates an error.You must supply a type name. SyncTime.ps1 -type NTP Using NTP to synchronize the time to the server "time.windows.com" SyncTime.ps1 -type NT5DS Using NT5DS to synchronize the time to domain hierarchy. SyncTime.ps1 -help ? Displays the help topic for the script. "@ $helpText exit } if($help) { "Obtaining help ..." funhelp } if(!$type) { Write-Host "A value for type is required. Try this: SyncTime.ps1 -help ?" -Foreground Yellow } switch($type) { "NTP" { ## set the shell execute policy set-executionpolicy remotesigned ## get the current path $mypath=get-location ## set the NTP server ## NTP = synchronize to manually configured source set-location hklm:system\currentcontrolset\services\w32time\Parameters set-itemproperty . Type NTP ## Set the AnnounceFlags. ##10(2+8) if thats the Default may just mean that it will not announce itself as a time server. ##0 Timeserv_Announce_No, Reliable_Timeserv_Announce_No. The domain controller does not advertise time service. ##1 Timeserv_Announce_Yes. The domain controller always advertises time service. ##2 Timeserv_Announce_Auto. The domain controller automatically determines whether it should advertise time service. ##4 Reliable_Timeserv_Announce_Yes. The domain contoller will always advertise reliable time service. ##8 Reliable_Timeserv_Announce_Auto. The domain controller automatically determines whether it should advertise reliable time service. cd ../Config set-itemproperty . AnnounceFlags 10 ## start the NTPServer cd ../TimeProviders/NtpServer set-itemproperty . Enabled 1 ## set the time source cd ../../Parameters set-itemproperty . NtpServer time.windows.com ## set the location of the path set-location $mypath.path ## stop and restart the w32time server net stop w32time net start w32time ## update the time with the NTP server w32tm /resync } "NT5DS" { ## set the shell execute policy set-executionpolicy remotesigned ## get the current path $mypath=get-location ## set the NTP server ## Nt5DS = synchronize to domain hierarchy [default] set-location hklm:system\currentcontrolset\services\w32time\Parameters set-itemproperty . Type NT5DS ## Set the AnnounceFlags. ## 5 is set the server announces itself as a reliable time source. cd ../Config set-itemproperty . AnnounceFlags 5 ## start the NTPServer cd ../TimeProviders/NtpServer set-itemproperty . Enabled 1 ## set the location of the path set-location $mypath.path ## stop and restart the w32time server net stop w32time net start w32time ## update the time with the NTP server w32tm /resync } DEFAULT { Write-Host "You must supply a value for the type to synchronize the time. Try this: SyncTime.ps1 -help ?" -Foreground Yellow } }
相关文章推荐
- 通过NTP协议进行时间同步
- 通过NTP协议进行时间同步
- python第三方库推荐 - 通过ntplib在windows上同步时间
- Linux内网服务器从Windows通过NTP同步时间
- 通过NTP协议进行时间同步
- Linux从Windows通过NTP同步时间
- python第三方库推荐 - 通过ntplib在windows上同步时间
- 通过NTP协议进行时间同步
- 通过网络NTP协议进行时间同步
- Windows局域网通过NTP设置时间同步
- python第三方库推荐 - 通过ntplib在windows上同步时间
- python第三方库推荐 - 通过ntplib在windows上同步时间
- 通过NTP协议进行时间同步
- Linux之通过NTP协议实现服务器时间同步的源码
- 在 Ubuntu 中使用 NTP 进行时间同步设置
- Linux的时间设置与同步(NTP)
- NTP服务及时间同步(CentOS6.x)
- 运用NTP进行时间同步
- ubuntu ntp 时间同步 搭建 使用
- ntpdate同步更新时间