04-06-2011
Downloads: 421
File size: 458 B
Views: 2,552
Embed
 |
Set Internet Time |
- function Get-InternetTime {
- $TcpClient = New-Object System.Net.Sockets.TcpClient
- [byte[]]$buffer = ,0 * 64
- $TcpClient.Connect('time.nist.gov', 13)
- $TcpStream = $TcpClient.GetStream()
- $length = $TcpStream.Read($buffer, 0, $buffer.Length);
- [void]$TcpClient.Close()
- $raw = [Text.Encoding]::ASCII.GetString($buffer)
- [DateTime]::ParseExact($raw.SubString(7,17), 'yy-MM-dd HH:mm:ss', $null).toLocalTime()
- }
-
- Set-Date (Get-InternetTime)
provides a function called Get-InternetTime which retrieves the current internet time from a time server and converts the raw time information into a valid local datetime. It then uses this information to set the local date and time (this requires local admin privileges)