-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeSyncChecker.ps1
More file actions
33 lines (29 loc) · 1.19 KB
/
TimeSyncChecker.ps1
File metadata and controls
33 lines (29 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
get-ADComputers -ExcludeClusters | % {
try {
$remoteTime = invoke-command -ComputerName $_ -ScriptBlock {get-date -format "HH:mm:ss"} -ErrorAction SilentlyContinue
#Start-Sleep -s 2 #for debugging
$currenttime = get-date -format "HH:mm:ss"
if (Get-variable -Name remotetime)
{
if ($currenttime -eq $remotetime)
{}
else
{
try {
$diff = New-timespan -Start $remoteTime -End $currenttime
Write-Host "difference" $diff "at" $_ $currenttime $remotetime
$tempsecond = New-TimeSpan -Seconds 1
$tempsecondnegative = New-TimeSpan -Seconds -1 #for covering backwards
if ($diff.TotalSeconds -gt $tempsecond.TotalSeconds -or $diff.TotalSeconds -lt $tempsecondnegative.TotalSeconds)
{Write-Warning "difference more than $tempsecond at $_" -Verbose}
}
catch
{}
#Write-Host $_ $currenttime $remotetime
}
}
}
#{$Error[4] | Select –Property *}
catch [System.Management.Automation.Remoting.PSRemotingTransportException]
{Write-Host $_ }
}