NTP status and settings in AD

After my previous post i came up with the idea to make a script that checks the whole AD for NTP Status and settings.

###
## test Domain Controller time
## revision 2.00 (on 27.02.2020)
## it shows the registry values as well
Function test_dc_time {
$StartTime = (Get-Date)
$LocalTime = Get-Date
write-host “The Local time is: “$LocalTime -BackgroundColor green -ForegroundColor Black
$servernames = Get-ADComputer -SearchBase “ou=domain controllers,dc=test,dc=com” -filter * | ForEach-Object { Get-ADDomainController -Identity $_.DNSHostname}
foreach($servername in $servernames){
if (Test-Connection $servername -count 1 -quiet){
Invoke-command -computername $servername -scriptblock{
Get-ItemProperty -path HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters\ -name * | Select-Object pscomputername, type, ntpserver
w32tm /query /status
write-host “#####################################################################################”
}
}
else{
write-host “Server offline: “$servername -BackgroundColor red -ForegroundColor Black
}
}
$([timespan]::fromseconds(((Get-Date)-$StartTime).Totalseconds).ToString(“mm\:ss”))
}

#if you want to use it just uncomment the following line
test_dc_time

Leave a Reply

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