refactor(wakeup): use cmdletbinding, change var db name

This commit is contained in:
Asif Bacchus 2021-09-06 16:03:34 -06:00
parent 47c313a26a
commit fc3a39b0b9

View File

@ -1,6 +1,7 @@
<# <#
#> #>
[CmdletBinding()]
param param
( (
# Array of strings listing computer name(s) to wake up. Names will be matched using RegEx # Array of strings listing computer name(s) to wake up. Names will be matched using RegEx
@ -8,7 +9,7 @@ param
[String[]] [String[]]
$TargetComputer = "", $TargetComputer = "",
# XML database file containing computer details (Default: WOLDatabase.xml) # XML database file containing computer details (Default: WOLDatabase.xml)
[Alias("List", "database", "db")] [Alias("List", "Database")]
[String] [String]
$WolDatabase = "WOLDatabase.xml", $WolDatabase = "WOLDatabase.xml",
# Skip connectivity check # Skip connectivity check
@ -90,14 +91,14 @@ if ( [String]::IsNullOrWhiteSpace($TargetComputer))
Write-Host Write-Host
# read database and assemble list of target computers # read database and assemble list of target computers
[xml]$db = Get-Content -Path $WolDatabase [xml]$wolDb = Get-Content -Path $WolDatabase
$broadcastIP = $db.WOLDatabase.Configuration.BroadcastAddress $broadcastIP = $wolDb.WOLDatabase.Configuration.BroadcastAddress
$port = $db.WOLDatabase.Configuration.Port $port = $wolDb.WOLDatabase.Configuration.Port
$dnsSuffix = $db.WOLDatabase.Configuration.DnsSuffix $dnsSuffix = $wolDb.WOLDatabase.Configuration.DnsSuffix
$targetComputers = [System.Collections.Generic.List[PSObject]]::new() $targetComputers = [System.Collections.Generic.List[PSObject]]::new()
$TargetComputer | ForEach-Object { $TargetComputer | ForEach-Object {
$tgt = $_ $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() $removeFromTargetComputers = [System.Collections.Generic.List[String]]::new()