refactor(wakeup): change var names
- change targetComputer var name to PascalCase for consistency - parameterize database location, change variable name to PascalCase
This commit is contained in:
parent
5003661a63
commit
130e346319
26
wakeup.ps1
26
wakeup.ps1
@ -6,9 +6,13 @@ param
|
|||||||
# Computer to wake up
|
# Computer to wake up
|
||||||
[Alias("Computer")]
|
[Alias("Computer")]
|
||||||
[String]
|
[String]
|
||||||
$targetComputer = "",
|
$TargetComputer = "",
|
||||||
# Skip RDP connectivity readiness check
|
# XML database file containing computer details
|
||||||
[Alias("Check", "Readiness")]
|
[Alias("List", "database", "db")]
|
||||||
|
[String]
|
||||||
|
$WolDatabase = "WOLDatabase.xml",
|
||||||
|
# Skip connectivity readiness check
|
||||||
|
[Alias("NoCheck", "NoReadiness")]
|
||||||
[Switch]
|
[Switch]
|
||||||
$ConnectivityCheck = $false,
|
$ConnectivityCheck = $false,
|
||||||
# RDP connectivity readiness check timeout
|
# RDP connectivity readiness check timeout
|
||||||
@ -56,35 +60,35 @@ if (!(Get-Module -Name $wolModuleName))
|
|||||||
}
|
}
|
||||||
|
|
||||||
# exit if database cannot be found/read
|
# 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
|
exitError $errMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
# get target computer name if not already specified
|
# get target computer name if not already specified
|
||||||
if ( [String]::IsNullOrWhiteSpace($targetComputer))
|
if ( [String]::IsNullOrWhiteSpace($TargetComputer))
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
$targetComputer = Read-Host -Prompt 'Computer to wake-up'
|
$TargetComputer = Read-Host -Prompt 'Computer to wake-up'
|
||||||
} while ( [String]::IsNullOrWhiteSpace($targetComputer))
|
} while ( [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]$db = Get-Content -Path $WolDatabase
|
||||||
$broadcastIP = $db.WOLDatabase.Configuration.BroadcastAddress
|
$broadcastIP = $db.WOLDatabase.Configuration.BroadcastAddress
|
||||||
$port = $db.WOLDatabase.Configuration.Port
|
$port = $db.WOLDatabase.Configuration.Port
|
||||||
$dnsSuffix = $db.WOLDatabase.Configuration.DnsSuffix
|
$dnsSuffix = $db.WOLDatabase.Configuration.DnsSuffix
|
||||||
$targetComputers = [System.Collections.Generic.List[PSObject]]::new()
|
$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()
|
$removeFromTargetComputers = [System.Collections.Generic.List[String]]::new()
|
||||||
|
|
||||||
# exit if nothing to do (i.e. empty targetComputers list)
|
# exit if nothing to do (i.e. empty targetComputers list)
|
||||||
if ($targetComputers.Count -eq 0)
|
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
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user