Set Internet Time


posted by Tobias
04-06-2011

Downloads: 296
File size: 458 B
Views: 1,852

Embed
Set Internet Time
  1. function Get-InternetTime
  2.   $TcpClient = New-Object System.Net.Sockets.TcpClient 
  3.   [byte[]]$buffer = ,0 * 64 
  4.   $TcpClient.Connect('time.nist.gov', 13) 
  5.   $TcpStream = $TcpClient.GetStream() 
  6.   $length = $TcpStream.Read($buffer, 0, $buffer.Length); 
  7.   [void]$TcpClient.Close() 
  8.   $raw = [Text.Encoding]::ASCII.GetString($buffer
  9.   [DateTime]::ParseExact($raw.SubString(7,17), 'yy-MM-dd HH:mm:ss', $null).toLocalTime() 
  10.  
  11. Set-Date (Get-InternetTime
Filed under: , , , ,
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)
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.