; load external functions via call if you don't copy/paste the content directly into this script
Call '.\FileIO.kxf'
Call '.\Ping.kxf'
; clear DONE flag
$Done = 0
; load list of monitored devices into an array
$aTargets = FileIO('.\ServerList.txt', 'R')
; Create a status array to match the targets
Dim $aStatus[UBound($aTargets)]
; Initialize the status array to Status:1
For $ = 0 to UBound($aStatus)
$aStatus[$P] = 1
Next
; loop until all devices are at Status:3
While Not $Done
Cls
$Done = 1 ; assume complete
; enumerate the list of targets
For $P = 0 to UBound($aTargets)
If Ping($Target) ; host is up - responds to Ping
If $aStatus[$P] = 2 ; prior status was down
$aStatus[$P] = 3 ; log the transition from down to up (Status:2 to Status:3)
EndIf
If $aStatus[$P] = 1 ; not rebooted yet
$Done = 0 ; this host hasn't rebooted, we're not done
EndIf
Else
$aStatus[$P] = 2 ; Host is down - set Status:2
$Done = 0 ; this host is (still) down, we're not done
EndIf
$Target ' is at Stage: ' $aStatus[$P] @CRLF
Next
Sleep 60 ; wait 60 seconds and do it all again
Loop
'All hosts have completed the reboot process.' @CRLF