There are some situations where you want to boot a remote computer that’s powered off, but don’t have the tools to do that. For example: Microsoft SCCM allows you to boot a remote computer (wake it up from power off) to install Windows Updates. If you don’t have SCCM, there are hundreds of alternative software solutions. I just don’t want to install any peace of software.

Look no further! We can power on remote computers through PowerShell! The script demonstrates how to remote boot a PC with a UDP packet we’re creating through the System.Net.Sockets.UdpClient programming interface (part of dot Net).

Just replace the MAC-address with the address of the computer you want to boot, start the script, and boot!

$MacAddress = [byte[]](0x00, 0x25, 0xB3, 0x0D, 0xA8, 0xF9)
$UDPclient = New-Object System.Net.Sockets.UdpClient
$UDPclient.Connect(([System.Net.IPAddress]::Broadcast),4000)
$packet = [byte[]](,0xFF * 102)
6..101 | foreach { $packet[$_] = $MacAddress[($_%6)]}
$UDPclient.Send($packet, $packet.Length)

2 Comments on Wake on LAN (WOL) using PowerShell

  1. Jon Biddell says:

    Strictly a Powershell n00b here, but learning fast (I hope !!). I have a question regarding this script.

    How hard would it be to get the script to accept a command line parameter and do a DNS lookup of the name ? So you could invoke it like;

    PS> ./wol.ps1 pch2222

    Just for waking a single machine on the company LAN – we hve a web-based tool, but it’s a pain in the ass and SLOW.

    • Hi Jon,
      Performing a DNS lookup from PowerShell is no problem at all, but it’s not going to solve the problem. Since DNS registers Name-IP address mappings, and for a WOL we need a MAC-address, so DNS will not provide us with the information.

      I think the only service that can help us out is DHCP. There is a PowerShell module for DHCP but I can not determine whether we can query for registered leases. I did find that we can query the DHCP database using netsh in combination with a “show clients” command.

      Let me know if this is of any help to you…