← script library

Send a Wake-on-LAN Magic Packet with PowerShell

System AdministrationAugust 17, 2026

Builds a proper magic packet — six 0xFF bytes followed by the MAC repeated sixteen times — and sends it by UDP broadcast. The MAC address is validated first and accepts either separator, and the log spells out the two reasons this usually fails: WOL disabled in the firmware, or a routed network that needs the subnet broadcast address instead of 255.255.255.255.

powershell
# Wake-on-LAN
# Single use case: send a WOL magic packet to wake one machine
#-----------------------------------------------------------------

function Write-Log {
    param($Message)
    Write-Host "<WRITE-LOG = `"*$Message*`">"
}

# --- Parameters (replace via ServerEngine API parameters if needed) ---
$MacAddress = "00-11-22-33-44-55"    # accepts : or - separators
$Broadcast  = "255.255.255.255"      # use the subnet broadcast for routed networks
$Port       = 9

$clean = $MacAddress -replace "[:-]", ""
if ($clean -notmatch "^[0-9A-Fa-f]{12}$") {
    Write-Log "Invalid MAC address: $MacAddress"
    return
}

$macBytes = for ($i = 0; $i -lt 12; $i += 2) { [Convert]::ToByte($clean.Substring($i, 2), 16) }

# magic packet = 6x 0xFF + 16x MAC
$packet = (,[byte]0xFF * 6) + ($macBytes * 16)

$udp = New-Object System.Net.Sockets.UdpClient
try {
    $udp.Connect($Broadcast, [int]$Port)
    [void]$udp.Send($packet, $packet.Length)
    Write-Log "Magic packet sent to $MacAddress via ${Broadcast}:${Port}."
    Write-Log "Note: the target needs WOL enabled in BIOS/NIC settings, and routed networks need the subnet broadcast address."
} catch {
    Write-Log "WARNING: failed to send packet: $($_.Exception.Message)"
} finally {
    $udp.Close()
}

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.