Clock Skew and You
We had an issue where the clocks on various hosts got offset beyond the margin allowed by an application we were testing. Here's a way to scan hosts for their clock skew relative to a known good server:
function Get-RemoteTime {
param (
[String[]]$computerName = @($env:COMPUTERNAME)
)
foreach ($computer in $computerName) {
if (!$computer) { continue; }
$localTime = Get-Date;
$time = Get-WmiObject -ComputerName $computer Win32_LocalTime;
$remoteTime = ("{0}/{1}/{2} {3}:{4}:{5}" -f $time.year, $time.month, $time.day, $time.hour, $time.minute, $time.second) -as [DateTime];
$skew = [Math]::Abs([int]($localTime - $remoteTime).TotalSeconds);
$computer | Select-Object @{
n = 'Computer';
e = { $_; }
}, @{
n = 'LocalTime';
e = { $localTime; }
}, @{
n = 'RemoteTime';
e = { $remoteTime; }
}, @{
n = 'Skew';
e = { $skew; }
}
}
}