Skip to content

Instantly share code, notes, and snippets.

@msh31
Created June 17, 2025 20:24
Show Gist options
  • Select an option

  • Save msh31/95c5fcd460eb1ed036999196b1ad2096 to your computer and use it in GitHub Desktop.

Select an option

Save msh31/95c5fcd460eb1ed036999196b1ad2096 to your computer and use it in GitHub Desktop.
WOL PowerShell
$MacAddress = "08:BF:B8:12:EC:71"
$MacAddress = $MacAddress.Replace(":", "")
$BroadcastAddress = "192.168.178.255"
$Port = 9
# Convert the MAC address to a byte array
$MacBytes = [byte[]]::new($MacAddress.Length / 2)
for ($i = 0; $i -lt $MacAddress.Length; $i += 2) {
$MacBytes[$i / 2] = [convert]::ToByte($MacAddress.Substring($i, 2), 16)
}
$Socket = New-Object System.Net.Sockets.UdpClient
$Socket.Connect($BroadcastAddress, $Port)
# Create the magic packet
$Packet = [byte[]](,0xFF * 6) + $MacBytes * 16
$Socket.Send($Packet, $Packet.Length) | Out-Null
$Socket.Close()
Write-Host "sent packet to $MacAddress"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment