I'm using the default clock drift script, trying to figure out where to change enter the time.nist.gov server as the time server. I see the $time_server = $args, but when I place the time.nist.gov I get an error saying error in call method. I guess the easiest way to ask my questions is just where do I input the time settings for clock drift and where do I input the time.nist.gov server? Dumb question I know, but I a newb. Thank you.
Below is the unedited script. I also looked for the documentation, but the page where it was originally posted is blank.
# Argument example: time.nist.gov
function Get-InternetTime ([string]$time_server) {
$TcpClient = New-Object System.Net.Sockets.TcpClient
[byte[]]$buffer = ,0 * 64
$TcpClient.Connect($time_server, 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()
}
$time_server = $args.get(0);
if ( !$time_server )
{
Write-Host "Message: Can't find ""time_server"" argument. Check documentation.";
exit 1;
}
$Error.Clear();
$a = Get-InternetTime $time_server;
$a_Y = $a.Year;
$a_M = $a.Month;
$a_D = $a.Day;
$a_h = $a.Hour;
$a_m = $a.Minute;
$a_s = $a.Second;
$a_t = $a.Ticks;
$b = [DateTime] (get-date);
$b_Y = $b.Year;
$b_M = $b.Month;
$b_D = $b.Day;
$b_h = $b.Hour;
$b_m = $b.Minute;
$b_s = $b.Second;
$b_t = $b.Ticks;
if ($Error.Count -ne 0) {
Write-Host "Message: Try to rerrun script. Error: $($Error[0])";
exit 1;
}
$server_time = (31104000*$a_Y)+(2592000*$a_M)+(86400*$a_D)+(3600*$a_h)+(60*$a_m)+$a_s;
$local_time = (31104000*$b_Y)+(2592000*$b_M)+(86400*$b_D)+(3600*$b_h)+(60*$b_m)+$b_s;
$clock_drift=$server_time-$local_time;
if ($clock_drift -lt 0)
{
$clock_drift=$clock_drift*(-1);
$symbol=$clock_drift;
}
else
{
$symbol="-",$clock_drift;
}
Write-Host "Message: Clock drift: $symbol s. Current date and time on target server: $b";
Write-Host "Statistic: $clock_drift";
exit 0;