Q. How can I easily send a magic packet to wake a machine on my subnet?

A. In a previous FAQ, I talked about the Wake On LAN (WOL) magic packet, which wakes a machine that's turned off by sending a packet with the machine's MAC address. The target machine must support WOL, and you may need to configure whether the machine should boot normally or from the network when it's started via WOL.

I wanted a little script to send the magic packet to turn on my wife's desktop machine upstairs when she wants to use it. (She's on bed rest, pregnant with twins, and I got tired of going up there to turn it on Smile). She uses a small laptop and remotes into her desktop computer, so shutting down the desktop was just a matter of  creating a shortcut to

shutdown /s /t 0

Starting it was trickier, however. After checking that the BIOS supported WOL, I made a note of the MAC address and created the PowerShell script below based on some snippets I found on the web. You just pass the MAC address in format xx:xx:xx:xx:xx:xx and it turns on the machine. Easy!

Below is my PowerShell script:

<p>param (\\[String\\]$MACAddrString = $(throw 'No MAC addressed passed, please pass as xx:xx:xx:xx:xx:xx'))<br> $MACAddr = $macAddrString.split(':') | %\\{ \\[byte\\]('0x' + $_) \\}<br> if ($MACAddr.Length -ne 6)<br> \\{<br>     throw 'MAC address must be format xx:xx:xx:xx:xx:xx'<br> \\}<br> $UDPclient = new-Object System.Net.Sockets.UdpClient<br> $UDPclient.Connect((\\[System.Net.IPAddress\\]::Broadcast),4000)<br> $packet = \\[byte\\[\\]\\](,0xFF * 6)<br> $packet += $MACAddr * 16<br> \\[void\\] $UDPclient.Send($packet, $packet.Length)<br> write "Wake-On-Lan magic packet sent to $MACAddrString, length $($packet.Length)"<br><br></p>

I saved it as wol.ps1. You need to make sure you enable script execution in your PowerShell environment:

 

<p>PS D:\Documents\scripts> <strong>Set-ExecutionPolicy unrestricted</strong><br><br> Execution Policy Change<br> The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose<br> you to the security risks described in the about_Execution_Policies help topic. Do you want to change the execution<br> policy?<br> \\[Y\\] Yes \\[N\\] No \\[S\\] Suspend \\[?\\] Help (default is "Y"): <strong>Y</strong></p>

And then, to turn on my wife's machine was just

<p>PS D:\Documents\scripts> <strong>.\wol.ps1 D8:D3:85:9A:98:60</strong><br> Wake-On-Lan magic packet sent to D8:D3:85:9A:98:60, length 102</p>

No more walking upstairs for me. You can customize the script to check for - instead of : by replacing the .split(':') to .split('-') in the code. You can also change it to any other combination that works for you.

Discuss this Article 4

riosf
on Jan 13, 2011
Take a look at http://depicus.com/wake-on-lan/welcome.aspx. Here you can find different ways to do WOL. They even have a monitor tool that allows you to test if a computer is getting the magic packet. And best of all, it is free!
thorarinn@emco.is
on Feb 21, 2011
There is a free WOL tool with UI that is able to detect MAC addresses automatically and wake up multiple PCs: http://www.wake-on-lan.net. Using this tool you can not only to wake up multiple PCs in the local subnet, but also wake up PCs in other subnets.
riosf
on Jan 13, 2011
Take a look at http://depicus.com/wake-on-lan/welcome.aspx. Here you can find different ways to do WOL. They even have a monitor tool that allows you to test if a computer is getting the magic packet. And best of all, it is free!
insc
on Jan 31, 2011
Another GUI and command line tool for easily usage of Wake On Lan is available at <a href= http://rshut.com>http://rshut.com</a>

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottYou'll have the opportunity to experience:
• The Microsoft
Technology Roadmap
• Office 365 Implementation
• Hyper-V Optimizing
• Windows 8 Deployment
and much more!

Come See Paul Thurrott & Rod Trent in Person!

Early Registration Now Open

Upcoming Training

Mastering System Center 2012

During over 6 hours of training you can join John Savill from your computer as he will walk you through the key components and capabilities of System Center 2012, what’s involved in using the components, and the benefit they can bring to your environment.

Register Now

Current Issue

May 2013 - The NameTranslate object is useful when you need to translate Active Directory object names between different formats, but it's awkward to use from PowerShell. Here's a PowerShell script that eliminates the awkwardness.

CURRENT ISSUE / ARCHIVE / SUBSCRIBE

Windows Forums

Get answers to questions, share tips, and engage with the Windows Community in our Forums.