
Param ( $MacString =$( Throw 'Mac address is required')).
# Send Wake-on-Lan Magic Packet to specified Mac address. It would be possible to use DNS and the ARP Cache to resolve MAC addresses but the ARP cache will only be populated with a valid entry for any given target adapter for a relative short period of time after the last use of the address (10 minutes or less depending on usage) ARP cannot be used to dynamically resolve the address of a suspended adapter. This script has a table of saved MAC addresses to allow aliases to be specified on the command line (the real addresses have been obfuscated here) and uses a regex to validate the resulting MAC address string. Construction of this packet in PowerShell is a breeze thanks to the array semantics in the language (“$Packet = ](,0xFF*6)+($Mac*16)” – neat). This packet is sent via UDP to the LAN Broadcast address (255.255.255.255) on arbitrary Port 4000 – although the layer 3 baggage is actually largely irrelevant. Wake on Lan uses a “Magic Packet” that consists of six bytes of 0xFF (the physical layer broadcast address), followed by 16 copies of the 6-byte (48-bit) MAC address (see ). I use this a lot – especially these days with spiralling electricity costs – to wake suspended machines and servers. Here’s my take on the theme in PowerShell (naturally:-)
There are a bunch of these to be found on the Web (see the additional notes on Origins below) although sadly some of them are either incorrect or of very dubious style.