From 2a21a234622f9db34edf73f92c535e21acc00461 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Sun, 5 Sep 2021 22:48:20 -0600 Subject: [PATCH] feature(wakeup): exit if no matching computers found --- wakeup.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/wakeup.ps1 b/wakeup.ps1 index 0a14542..34543b1 100644 --- a/wakeup.ps1 +++ b/wakeup.ps1 @@ -75,6 +75,13 @@ $targetComputers = [System.Collections.Generic.List[PSObject]]::new() $db.WOLDatabase.Computers.Computer | Where-Object { $_.name -match "$targetComputer" } | ForEach-Object { $targetComputers.Add($_) } $removeFromTargetComputers = [System.Collections.Generic.List[String]]::new() +# exit if nothing to do (i.e. empty targetComputers list) +if ($targetComputers.Count -eq 0) +{ + Write-Host -ForegroundColor Yellow "No computers found matching '$targetComputer'. Nothing to do.`r`n" + exit 0 +} + # send WOL magic packets $targetComputers | ForEach-Object { $wolError = @()