57 lines
1.9 KiB
PowerShell
57 lines
1.9 KiB
PowerShell
####SCRIPT PER CONTROLLARE TIME DRIFT WINDOWS####
|
|
|
|
#nome file di log
|
|
$logFile = "W32TimeDriftCheck.log"
|
|
#cartella file di log
|
|
$logFolder = "c:\Steamware\Logs\"
|
|
#opzione log su file: scrivo se = 1, ignoro se = 0
|
|
$logType = 1
|
|
#opzione output in terminale: scrivo se = 1, ignoro se = 0
|
|
$terminalOutput = 1
|
|
#Ipv4 PDC
|
|
$PDC = "10.74.82.251"
|
|
#Ipv4 BDC
|
|
$BDC = "10.74.82.250"
|
|
#Nome host su Zabbix per invio con trapper
|
|
$ZabbixHost = "WIN2022-SQL-DEV"
|
|
|
|
#creazione folder di Log se non già esistente
|
|
if (Test-Path $logFolder) {
|
|
}
|
|
else {
|
|
New-Item $logFolder -ItemType Directory
|
|
}
|
|
|
|
#funzione locale per log su file e output su terminale
|
|
Function WriteLogOutput {
|
|
Param ([string]$logString)
|
|
#compongo path per file di log
|
|
$logPath = Join-Path $logFolder $logFile
|
|
#scrivo su file la stringa se $logType=1
|
|
if ($logType -eq 1) {
|
|
Add-content $logPath -value "$logString"
|
|
}
|
|
#scrivo su terminale la stringa se $terminalOutput=1
|
|
if ($terminalOutput -eq 1) {
|
|
Write-Output($logString)
|
|
}
|
|
}
|
|
|
|
#rilevo tempo locale e differenza PDC, restituisco in secondi
|
|
$localTime, $timeDifferencePDC = (& w32tm /stripchart /computer:$PDC /samples:1 /dataonly)[-1].Trim("s") -split ',\s*'
|
|
#rilevo tempo locale e differenza BDC, restituisco in secondi
|
|
$localTime, $timeDifferenceBDC = (& w32tm /stripchart /computer:$BDC /samples:1 /dataonly)[-1].Trim("s") -split ',\s*'
|
|
|
|
#scrivo log data e ora
|
|
WriteLogOutput ""
|
|
WriteLogOutput "Script Execution: $localTime"
|
|
|
|
#invio a zabbix i dati
|
|
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s $ZabbixHost -k W32.TimeDifferencePDC -o $timeDifferencePDC
|
|
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s $ZabbixHost -k W32.TimeDifferenceBDC -o $timeDifferenceBDC
|
|
|
|
#output differenza PDC
|
|
WriteLogOutput "Time Difference W2022PDC: $timeDifferencePDC s"
|
|
#output differenza BDC
|
|
WriteLogOutput "Time Difference W2022BDC: $timeDifferenceBDC s"
|
|
WriteLogOutput "" |