Created 2 scripts, one that will check which time source is being used, and one that measures the time difference. But now it want to combine those script and i'm not sure how to do it. I want the output to be something like :
DC01 optimal time synchronisation, uses DC02 as the timesource.
Timecheck difference script
$servers = "DC01","DC02","DC04"
$w32tm = invoke-command -computername $servers -scriptblock{w32tm /monitor /computers:$servers /nowarn}
$icmp = ($w32tm -like "*ICMP*") -replace "ICMP:",""
If($icmp -le "0ms"){$timestatus="Optimal time synchronisation"}
IF($icmp -gt "300000ms"){$timestatus="Critical. Over 5 minutes time difference!"}
If($icmp -gt "100000ms"){$timestatus="Warning, 2 minutes time difference"}
foreach($server in $servers){
Write-Host $timestatus for $server
}
NTP Source script
$Computername = "dc01","dc02","dc04"
foreach ($Computer in $Computername)
{
$ntps = w32tm /query /computer:$Computer /source
new-object psobject -property @{
Name = $Computer
NTPSource = $ntps
}
}