WOL via Powershell

I love Powershell and I’m sure a lot of you do too. I geek out over nearly every script I create but there are some that I get as giddy as a schoolgirl over; this is one of them. I work at a client’s site that has hundreds of IP networks and with network admins that don’t want to open up multicasting. I’ve attempted to mess with WOL unicast but I just couldn’t ever get it working so I decided to figure out how to get this to work via Powershell.

If you’re familiar with WOL, you’ll know that the WOL magic packet is not routable. It either has to be subnet-directed out which a lot of network admins won’t allow or sent from a device on the same logical network as the device you’re wanting to wake up. You end up only being able to wake up computers on the same subnet as you. If you’re in a large enterprise, that’s near worthless.

I created this script to wake up any PC on any subnet inside an enterprise network regardless of where it is. It does this by first checking to see if your PC is already on the same subnet as the PC you want to wake up. If so, it just initiates a WOL traditionally. However, if it detects the offline PC is on a different subnet, it attempts to find any other online, Windows PCs on that subnet, copy a small WOL utility to it and initiate the WOL attempt from THAT subnet. This gets around the non-routable, no multicasting requirement. It also allows you to use Powershell remoting to do this or, if you don’t have remoting enabled, it’ll use a WMI RPC call to create the WOL process on the WOL proxy computer.

I haven’t extensively tested the remoting capability yet and there’s a few things I’d like to tweak on it but overall, it functions very well now. I’ll make sure to keep this post up to date if I decided to improve upon it.

Don't just learn from my blog and keep that newfound knowledge to yourself! Share it! I've created a new service called TechSnips that's dedicated to helping technology professionals share their knowledge and look awesome in the process! Through small screencast videos, full courses and written content, TechSnips is a community to help you grow your career. Join us!.

10/01/14 UPDATE: Bug fix that prevented WOL from being used on local subnets.

Download this script on the Technet Script Repository

%d bloggers like this: