feature(wakeup): run multiple connectivity checks up to timeout
This commit is contained in:
parent
0119923ed7
commit
5332818990
71
wakeup.ps1
71
wakeup.ps1
@ -131,6 +131,7 @@ $targetComputers | ForEach-Object {
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Write-Host -ForegroundColor Red "[ERROR]"
|
Write-Host -ForegroundColor Red "[ERROR]"
|
||||||
|
# queue for removal from computers on which to run a connectivity check
|
||||||
$removeFromTargetComputers.Add($name)
|
$removeFromTargetComputers.Add($name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,7 +153,7 @@ elseif ($targetComputers.Count -eq 0)
|
|||||||
exitError "No wake-up packets sent successfully" -exitCode 5
|
exitError "No wake-up packets sent successfully" -exitCode 5
|
||||||
}
|
}
|
||||||
|
|
||||||
# wait for initialWaitTime seconds to let computer(s) wake up
|
# wait for initial delay seconds to let computer(s) wake up
|
||||||
for ($i = $ConnectivityCheckDelay; $i -gt 0; $i--) {
|
for ($i = $ConnectivityCheckDelay; $i -gt 0; $i--) {
|
||||||
Write-Progress -Activity "Waiting for computer(s) to wake-up..." -SecondsRemaining $i
|
Write-Progress -Activity "Waiting for computer(s) to wake-up..." -SecondsRemaining $i
|
||||||
Start-Sleep 1
|
Start-Sleep 1
|
||||||
@ -162,33 +163,55 @@ Write-Progress -Activity "Waiting for computer(s) to wake-up..." -Completed
|
|||||||
# iterate computers and test connectivity
|
# iterate computers and test connectivity
|
||||||
# TODO: run multiple connectivity tests as needed, spaced evenly apart up to max timeout THEN fail
|
# TODO: run multiple connectivity tests as needed, spaced evenly apart up to max timeout THEN fail
|
||||||
# TODO: run connectivity test as background job
|
# TODO: run connectivity test as background job
|
||||||
|
$connCheckTotalTime = 0
|
||||||
|
$removeFromTargetComputers.Clear()
|
||||||
|
while ($connCheckTotalTime -le $ConnectivityCheckTimeout -and $targetComputers.Count -gt 0)
|
||||||
|
{
|
||||||
|
$targetComputers | ForEach-Object {
|
||||||
|
$name = $_.name
|
||||||
|
$friendlyName = $_.friendlyName
|
||||||
|
$fqdn = -join ($name, $dnsSuffix)
|
||||||
|
$connectionError = @()
|
||||||
|
|
||||||
|
if ( [String]::IsNullOrWhiteSpace($friendlyName))
|
||||||
$targetComputers | ForEach-Object {
|
{
|
||||||
$name = $_.name
|
Write-Host "Testing connection readiness of '$name'... " -NoNewline
|
||||||
$friendlyName = $_.friendlyName
|
}
|
||||||
$fqdn = -join ($name, $dnsSuffix)
|
else
|
||||||
$connectionError = @()
|
{
|
||||||
|
Write-Host "Testing connection readiness of '$friendlyName'... " -NoNewline
|
||||||
if ( [String]::IsNullOrWhiteSpace($friendlyName))
|
}
|
||||||
{
|
if (!(Test-NetConnection -ComputerName $fqdn -Port $ConnectivityCheckPort -InformationLevel Quiet -WarningAction SilentlyContinue -ErrorAction SilentlyContinue -ErrorVariable +connectionError))
|
||||||
Write-Host "Testing connection readiness of '$name'... " -NoNewline
|
{
|
||||||
}
|
Write-Host -ForegroundColor Red "[ERROR]"
|
||||||
else
|
$connectionError | ForEach-Object {
|
||||||
{
|
$errMsg = $_.ToString()
|
||||||
Write-Host "Testing connection readiness of '$friendlyName'... " -NoNewline
|
Write-Host -ForegroundColor Red "`tAdditional information: $errMsg"
|
||||||
}
|
}
|
||||||
if (!(Test-NetConnection -ComputerName $fqdn -Port $ConnectivityCheckPort -InformationLevel Quiet -WarningAction SilentlyContinue -ErrorAction SilentlyContinue -ErrorVariable +connectionError))
|
}
|
||||||
{
|
else
|
||||||
Write-Host -ForegroundColor Red "[ERROR]"
|
{
|
||||||
$connectionError | ForEach-Object {
|
Write-Host -ForegroundColor Green "[OK]"
|
||||||
$errMsg = $_.ToString()
|
# queue for removal from computers to check next round
|
||||||
Write-Host -ForegroundColor Red "`tAdditional information: $errMsg"
|
$removeFromTargetComputers.Add($name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
# remove computers from targetComputers if connectivity check already successful
|
||||||
|
$removeFromTargetComputers | ForEach-Object {
|
||||||
|
$removeName = $_
|
||||||
|
$targetComputers.Remove(($targetComputers | Where-Object { $_.name -eq $removeName })) | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# sleep until next test interval and increase time counter
|
||||||
|
if ($targetComputers.Count -gt 0)
|
||||||
{
|
{
|
||||||
Write-Host -ForegroundColor Green "[OK]"
|
for ($i = $ConnectivityCheckInterval; $i -gt 0; $i--) {
|
||||||
|
Write-Progress -Activity "Waiting for next connectivity check..." -SecondsRemaining $i
|
||||||
|
Start-Sleep 1
|
||||||
|
}
|
||||||
|
Write-Progress -Activity "Waiting for next connectivity check..." -Completed
|
||||||
|
$connCheckTotalTime += $ConnectivityCheckInterval
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user