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
(
# 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()