by Ramrod at 2013-03-06 01:52:52
Hi there,by Klaas at 2013-03-06 02:41:41
I’m trying to build a script, which syncs the windows system time with the internet. So far I found this:
function sync-time(
[string] $server = "nist1-ny.ustiming.org",
[int] $port = 37,
[switch] $set = $false)
{
$servertime = get-time -server $server -port $port -set:$set
write-host "Server time:" $servertime
write-host "Local time :" $(date)
}
Problem 1: The servertime remains empty
Problem 2: I don’t know how to change my system time with this script
Thanks in advance for any kind of help
Did you write or import a Get-Time cmdlet? There doesn’t seem to be one on my computer.by Ramrod at 2013-03-06 02:54:15
To sync the system clock and configure all sync settings, you can use w32tm.w32tm /?
[quote="Klaas"]Did you write or import a Get-Time cmdlet? There doesn’t seem to be one on my computer.by Klaas at 2013-03-06 04:27:57
To sync the system clock and configure all sync settings, you can use w32tm.w32tm /?[/quote]
I don’t know. The ISE gave me no error, while running the function. The w32tm seems useful, but I’m not good enough with Powershell to work out the whole
script by myself. Could you give me a hint ?
The point is I don’t think Powershell will be that usefull. The settings for time synchronisation are in the Windows registry (HKLM\System\CurrentControlSet\Services\W32Time On Windows7). If you wish to change those settings, you use the w32tm. You can do that from a Powershell window or cmd.exe. I don’t think it’s a good idea to interfere with time sync via scripts or scheduled tasks.
withw32tm /query /configurationorw32tm /monitoryou collect some usefull information and withw32tm /configyou can alter the settings, but I suggest you only do that if you’re aware of the dangers.