refactor(wakeup): rework params, conn-check multiple err msg
- rename connectivity check parameters for consistency - allow multiple errors to be reported for connectivity check for troubleshooting
This commit is contained in:
parent
4a8fff4384
commit
0119923ed7
41
wakeup.ps1
41
wakeup.ps1
@ -7,24 +7,30 @@ param
|
||||
[Alias("Computer")]
|
||||
[String[]]
|
||||
$TargetComputer = "",
|
||||
# XML database file containing computer details
|
||||
# XML database file containing computer details (Default: WOLDatabase.xml)
|
||||
[Alias("List", "database", "db")]
|
||||
[String]
|
||||
$WolDatabase = "WOLDatabase.xml",
|
||||
# Skip connectivity readiness check
|
||||
# Skip connectivity check
|
||||
[Alias("NoCheck", "NoReadiness")]
|
||||
[Switch]
|
||||
$NoConnectivityCheck = $false,
|
||||
# Initial wait period in seconds before first connectivity check
|
||||
$NoConnectivityCheck,
|
||||
# Delay before running first connectivity check (Default: 10)
|
||||
[Alias("Delay")]
|
||||
[Int]
|
||||
$WaitBeforeConnectivityCheck = 10,
|
||||
# connectivity readiness check total timeout
|
||||
$ConnectivityCheckDelay = 10,
|
||||
# Seconds before aborting connectivity check (Default: 300)
|
||||
[Alias("Timeout")]
|
||||
[Int]
|
||||
$Timeout = 300,
|
||||
# connectivity readiness port to check
|
||||
$ConnectivityCheckTimeout = 300,
|
||||
# Seconds between connectivity checks (Default: 30)
|
||||
[Alias("Interval")]
|
||||
[Int]
|
||||
$ConnectivityCheckInterval = 30,
|
||||
# Port to use for connectivity check (Default: 3389-RDP)
|
||||
[Alias("CheckPort")]
|
||||
[Int]
|
||||
$ConnectivityPort = 3389
|
||||
$ConnectivityCheckPort = 3389
|
||||
)
|
||||
|
||||
function exitError($errMessage, $PSItem, $exitCode = 1)
|
||||
@ -143,22 +149,26 @@ if ($NoConnectivityCheck)
|
||||
}
|
||||
elseif ($targetComputers.Count -eq 0)
|
||||
{
|
||||
exitError "No successful wake-up packets sent" -exitCode 5
|
||||
exitError "No wake-up packets sent successfully" -exitCode 5
|
||||
}
|
||||
|
||||
# wait for initialWaitTime seconds to let computer(s) wake up
|
||||
for ($i = $WaitBeforeConnectivityCheck; $i -gt 0; $i--) {
|
||||
for ($i = $ConnectivityCheckDelay; $i -gt 0; $i--) {
|
||||
Write-Progress -Activity "Waiting for computer(s) to wake-up..." -SecondsRemaining $i
|
||||
Start-Sleep 1
|
||||
}
|
||||
Write-Progress -Activity "Waiting for computer(s) to wake-up..." -Completed
|
||||
|
||||
# iterate computers and test connectivity
|
||||
# TODO: run multiple connectivity tests as needed, spaced evenly apart up to max timeout THEN fail
|
||||
# TODO: run connectivity test as background job
|
||||
|
||||
|
||||
$targetComputers | ForEach-Object {
|
||||
$name = $_.name
|
||||
$friendlyName = $_.friendlyName
|
||||
$fqdn = -join ($name, $dnsSuffix)
|
||||
$connectionError = ""
|
||||
$connectionError = @()
|
||||
|
||||
if ( [String]::IsNullOrWhiteSpace($friendlyName))
|
||||
{
|
||||
@ -168,10 +178,13 @@ $targetComputers | ForEach-Object {
|
||||
{
|
||||
Write-Host "Testing connection readiness of '$friendlyName'... " -NoNewline
|
||||
}
|
||||
if (!(Test-NetConnection -ComputerName $fqdn -Port $ConnectivityPort -InformationLevel Quiet -WarningAction SilentlyContinue -ErrorAction SilentlyContinue -ErrorVariable connectionError))
|
||||
if (!(Test-NetConnection -ComputerName $fqdn -Port $ConnectivityCheckPort -InformationLevel Quiet -WarningAction SilentlyContinue -ErrorAction SilentlyContinue -ErrorVariable +connectionError))
|
||||
{
|
||||
Write-Host -ForegroundColor Red "[ERROR]"
|
||||
Write-Host -ForegroundColor Red "`tAdditional information:", $connectionError[-1].ToString()
|
||||
$connectionError | ForEach-Object {
|
||||
$errMsg = $_.ToString()
|
||||
Write-Host -ForegroundColor Red "`tAdditional information: $errMsg"
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user