Compare commits

..

2 Commits

Author SHA1 Message Date
b968fdf93e chore(manifest): bump magicPacket to version 2.0 2021-09-05 18:50:09 -06:00
d5c3c071cd refactor(magicpacket): manual MAC address format validation
- use manual format validation for MacAddress so that ErrorAction works
correctly instead of throwing ParameterBindingError which requires
Try/Catch blocks

BREAKING CHANGES:
- remove parameter validation check for MacAddress,
validate while processing
- change all warnings to errors

Closes #1
2021-09-05 18:49:00 -06:00
2 changed files with 9 additions and 3 deletions

Binary file not shown.

View File

@ -50,7 +50,6 @@ function Send-MagicPacket
ValueFromPipelineByPropertyName,
HelpMessage = "Please provide one or more MAC addresses. You may use a colon (:) or a hypen (-) to separate hex values."
)]
[ValidatePattern('^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$')]
[String[]]
$MacAddress,
@ -83,6 +82,13 @@ function Send-MagicPacket
{
foreach ($addr in $MacAddress)
{
# validate MAC address format or write error and continue
if (!($addr -match '^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$'))
{
Write-Error "Invalid MAC address: $addr"
continue
}
# convert MAC address to magic packet
try
{
@ -97,7 +103,7 @@ function Send-MagicPacket
}
catch
{
Write-Warning "Unable to process MAC address: $thisMacAddress"
Write-Error "Unable to process MAC address: $thisMacAddress"
continue
}
@ -112,7 +118,7 @@ function Send-MagicPacket
}
catch
{
Write-Warning "Unable to send magic packet for '$addr'"
Write-Error "Unable to send magic packet for '$addr'"
continue
}
}