Created
June 17, 2025 20:24
-
-
Save msh31/95c5fcd460eb1ed036999196b1ad2096 to your computer and use it in GitHub Desktop.
WOL PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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