From cccd7ca3d69d7d32434ee4f3209e6d343c80f293 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Mon, 6 Sep 2021 16:08:33 -0600 Subject: [PATCH] feature(wakeup): only display connection err on last iteration --- wakeup.ps1 | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/wakeup.ps1 b/wakeup.ps1 index 6eea3b5..e80a040 100644 --- a/wakeup.ps1 +++ b/wakeup.ps1 @@ -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