Time Check

A simple powershell script to check the time settings on all your domaincontroller.

 

# Fnetonline
# Mark de Bruin
# Check Time
# Version 1.0
# Last updated 28-07-2019
# Simple powershell script to check the time and timesource on all domain controllers
# for more information please visit http://tools.fnetonline.nl/script/008

# get all domain controllers in the current domain
$DomainControllers = Get-ADDomainController -Filter * | Select-Object -expand name
$returnObj = @()
foreach ($DomainController in $DomainControllers)
{
# check the current source of time
$source = w32tm /query /computer:$DomainController /source
# Compare the current time with the local time
$timedif = w32tm /stripchart /computer:$DomainController /dataonly /samples:1|find “, “
# remove the current time and the letter S so we can use it for calculations
$dif = $timedif.split(“,”) -replace ‘[s]’,”

# check if the time is not drifting more than a minute from the local time
If (([single]$dif[1] -le 60) -and ([single]$dif[1] -ge -60))
{
# Great nothing to worry about
$state = ” “
}
Else
{
# whoops that isn’t good. please check the timesource
$State = “X”
}

# collect the results
$obj = New-Object psobject -Property @{
“X” = $State;
“DC” = $DomainController;
“Source” = $source;
“Offset” = [single]$dif[1];
}
$returnObj += $obj | select X,DC,Source,Offset

}
# clean up the screen
cls

# and make a nice table
$returnObj | Format-Table -AutoSize

# do not close the screen so we can review the results
pause

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *