Mittwoch, August 17, 2016

Get-NtpTime , Powershell Funktion

Wie spät ist es eigentlich? Manchmal setzt die ntp- Abfrage einfach aus und die PC Zeit läuft so nach und nach hinterher, oder auf und davon. Also gelegentlich prüfen, z.B. mit folgender Funktion:
#ibjs.net 20160817 Abfragefunktion für NTP, Auswertung der deutschen w32tm Ausgabe
$NTP_Server=@("ptbtime1.ptb.de", "ptbtime2.ptb.de", "ptbtime3.ptb.de", `
"pool.ntp.org","europe.pool.ntp.org","de.pool.ntp.org ",`
"time-a.nist.gov","time-b.nist.gov ")
Function Get-NtpTime{
Param($Server)
If (! $Server){$Server="ptbtime1.ptb.de"}
$NTPResponse={(iex "w32tm /stripchart /computer:$Server /dataonly /samples:0")[2]}
$NTPTime={get-date([regex]::Replace("$(&$NTPResponse)","([\D\s]+)([\d\. :]+)\.",'$2'))}
&$NTPTime
}
$NTP_Server|%{"{0,-20}{1}" -f $_,(Get-NtpTime $_)}
view raw Get-NtpTime.ps1 hosted with ❤ by GitHub

Keine Kommentare: