From fc3a39b0b955e1e364174e853376a270b6a8ac6a Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Mon, 6 Sep 2021 16:03:34 -0600 Subject: [PATCH] refactor(wakeup): use cmdletbinding, change var db name --- wakeup.ps1 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/wakeup.ps1 b/wakeup.ps1 index df5b2a9..52e897e 100644 --- a/wakeup.ps1 +++ b/wakeup.ps1 @@ -1,6 +1,7 @@ <# #> +[CmdletBinding()] param ( # Array of strings listing computer name(s) to wake up. Names will be matched using RegEx @@ -8,7 +9,7 @@ param [String[]] $TargetComputer = "", # XML database file containing computer details (Default: WOLDatabase.xml) - [Alias("List", "database", "db")] + [Alias("List", "Database")] [String] $WolDatabase = "WOLDatabase.xml", # Skip connectivity check @@ -90,14 +91,14 @@ if ( [String]::IsNullOrWhiteSpace($TargetComputer)) Write-Host # read database and assemble list of target computers -[xml]$db = Get-Content -Path $WolDatabase -$broadcastIP = $db.WOLDatabase.Configuration.BroadcastAddress -$port = $db.WOLDatabase.Configuration.Port -$dnsSuffix = $db.WOLDatabase.Configuration.DnsSuffix +[xml]$wolDb = Get-Content -Path $WolDatabase +$broadcastIP = $wolDb.WOLDatabase.Configuration.BroadcastAddress +$port = $wolDb.WOLDatabase.Configuration.Port +$dnsSuffix = $wolDb.WOLDatabase.Configuration.DnsSuffix $targetComputers = [System.Collections.Generic.List[PSObject]]::new() $TargetComputer | ForEach-Object { $tgt = $_ - $db.WOLDatabase.Computers.Computer | Where-Object { $_.name -match $tgt } | ForEach-Object { $targetComputers.Add($_) } + $wolDb.WOLDatabase.Computers.Computer | Where-Object { $_.name -match $tgt } | ForEach-Object { $targetComputers.Add($_) } } $removeFromTargetComputers = [System.Collections.Generic.List[String]]::new()