feature(wakeup): only display connection err on last iteration

This commit is contained in:
Asif Bacchus 2021-09-06 16:08:33 -06:00
parent 140edc1cb1
commit cccd7ca3d6
1 changed files with 13 additions and 5 deletions

View File

@ -162,7 +162,6 @@ for ($i = $ConnectivityCheckDelay; $i -gt 0; $i--) {
Write-Progress -Activity "Waiting for computer(s) to wake-up..." -Completed
# iterate computers and test connectivity
# TODO: report error/fail only after final run
# TODO: run connectivity test as background job
$connCheckTotalTime = 0
$removeFromTargetComputers.Clear()
@ -184,10 +183,19 @@ do
}
if (!(Test-NetConnection -ComputerName $fqdn -Port $ConnectivityCheckPort -InformationLevel Quiet -WarningAction SilentlyContinue -ErrorAction SilentlyContinue -ErrorVariable +connectionError))
{
Write-Host -ForegroundColor Red "[ERROR]"
$connectionError | ForEach-Object {
$errMsg = $_.ToString()
Write-Verbose "`t(Additional information: $errMsg)"
if (($connCheckTotalTime + $ConnectivityCheckInterval) -gt $ConnectivityCheckTimeout)
{
# last iteration, display 'error'
Write-Host -ForegroundColor Red "[ERROR]"
$connectionError | ForEach-Object {
$errMsg = $_.ToString()
Write-Verbose "`t(Additional information: $errMsg)"
}
}
else
{
# more iterations pending, display 'retrying'
Write-Host -ForegroundColor Yellow "[RETRYING]"
}
}
else