8
0
2024-01-24 16:42:38 +01:00

26 lines
1.9 KiB
PowerShell
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function Send-WOL {
param (
[parameter(
mandatory=$true,
position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[ValidateLength(17,17)]
[ValidatePattern("^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$")]
[array]$MACAddress
)
foreach ($MAC in $MACAddress) {
try {
$MAC = $mac.split(':') | %{ [byte]('0x' + $_) }
$UDPclient = new-Object System.Net.Sockets.UdpClient
$UDPclient.Connect(([System.Net.IPAddress]::Broadcast),4000)
$Packet = [byte[]](,0xFF * 6)
$Packet += $MAC * 16
Write-Verbose ([bitconverter]::tostring($Packet))
[void] $UDPclient.Send($Packet, $Packet.Length)
Write-Output "WOL command sent to $MAC"
} catch [system.exception] {
Write-Output "ERROR: Unable to send WOL command to $MAC"
}
}
}