The number of samples in the stripchart command will greatly impact the run time if you are running it against a large number of computers. I put it at 3 due to false non-responsive alerts when it was set to 1. If your network is repsonsive, 1 may be sufficient.
function get-timeoffset {
param([parameter(mandatory=$true)]$computer)
write-verbose "working on server $computer"
$resultval = new-object PSobject
add-member -input $resultval NoteProperty Computer $computer
$a = w32tm /stripchart /computer:$computer /dataonly /samples:3 /ipprotocol:4
if (-not ($a -is [array])) {
add-member -input $resultval NoteProperty Status "Offline"
add-member -input $resultval NoteProperty Offset $null
} else {
$foundtime=$false
#go through the 5 samples to find a response with timeoffset.
for ($i = 3; $i -lt 8; $i++) {
if (-not $foundtime) {
if ($a[$i] -match ", ([-+]\d+\.\d+)s") {
$offset = [float]$matches[1]
add-member -input $resultval NoteProperty Status "Online"
add-member -input $resultval NoteProperty Offset $offset
$foundtime=$true
}
}
}
#if no time samples were found, check for error
if (-not $foundtime) {
if ($a[3] -match "error") {
#0x800705B4 is not advertising/responding
add-member -input $resultval NoteProperty Status "NTP not responding"
} else {
add-member -input $resultval NoteProperty Status $a[3]
}
add-member -input $resultval NoteProperty Offset $null
}
}
$resultval
}
No comments:
Post a Comment