diff --git a/wakeup.ps1 b/wakeup.ps1 index 4d1c464..89139ad 100644 --- a/wakeup.ps1 +++ b/wakeup.ps1 @@ -6,9 +6,13 @@ param # Computer to wake up [Alias("Computer")] [String] - $targetComputer = "", -# Skip RDP connectivity readiness check - [Alias("Check", "Readiness")] + $TargetComputer = "", +# XML database file containing computer details + [Alias("List", "database", "db")] + [String] + $WolDatabase = "WOLDatabase.xml", +# Skip connectivity readiness check + [Alias("NoCheck", "NoReadiness")] [Switch] $ConnectivityCheck = $false, # RDP connectivity readiness check timeout @@ -56,35 +60,35 @@ if (!(Get-Module -Name $wolModuleName)) } # exit if database cannot be found/read -if (!(Test-Path -Path $wolDatabase -PathType Leaf)) +if (!(Test-Path -Path $WolDatabase -PathType Leaf)) { - $errMessage = "Unable to find or read Wake-On-LAN database file ($wolDatabase)" + $errMessage = "Unable to find or read Wake-On-LAN database file ($WolDatabase)" exitError $errMessage } # get target computer name if not already specified -if ( [String]::IsNullOrWhiteSpace($targetComputer)) +if ( [String]::IsNullOrWhiteSpace($TargetComputer)) { do { - $targetComputer = Read-Host -Prompt 'Computer to wake-up' - } while ( [String]::IsNullOrWhiteSpace($targetComputer)) + $TargetComputer = Read-Host -Prompt 'Computer to wake-up' + } while ( [String]::IsNullOrWhiteSpace($TargetComputer)) } Write-Host # read database and assemble list of target computers -[xml]$db = Get-Content -Path $wolDatabase +[xml]$db = Get-Content -Path $WolDatabase $broadcastIP = $db.WOLDatabase.Configuration.BroadcastAddress $port = $db.WOLDatabase.Configuration.Port $dnsSuffix = $db.WOLDatabase.Configuration.DnsSuffix $targetComputers = [System.Collections.Generic.List[PSObject]]::new() -$db.WOLDatabase.Computers.Computer | Where-Object { $_.name -match "$targetComputer" } | ForEach-Object { $targetComputers.Add($_) } +$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" + Write-Host -ForegroundColor Yellow "No computers found matching '$TargetComputer'. Nothing to do.`r`n" exit 0 }