Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Script to Wake on LAN on Several Subnets

I ran into a weird use case recently where I needed to perform a large-scale WoL for a bunch of lab computers after a scheduled campus-wide power outage. Well, I guess I didn't need to, but the alternative was to have someone run around and press hundreds of power buttons.

I immediately thought to use PDQ for this. I was able to build a PDQ Deploy package to wake computers fairly trivially, but then I ran into another issue. Every single computer on the lab computers subnet will be offline. PDQ relies on being able to use another computer on that subnet to relay WoL packets, since it can't be done cross-subnet. If every computer on that subnet is offline, PDQ can't wake them.

So, I had the bright idea to add a virtual NIC to our PDQ server on the lab computers subnet. Surely then PDQ could just send WoL packets directly to those computers without needing to relay the packets through another computer first? Nope, no dice. I asked PDQ support about it and the only way to make that work would be to change the NIC binding order to put the lab computers subnet NIC at the top. That is not ideal for several reasons-- I want my PDQ server to do most of its work from its IP on the servers subnet, and I also want this to be extensible so that it can handle several subnets, not just one. Unless I program something in to dynamically swap NIC binding order (which I very much do not want to do), that is not a viable solution.

So, I decided to build a PowerShell script that just takes a PDQ Inventory report as input and then wakes each computer in the report. The script automatically determines which NIC to send the packets from based on the IP address of the target computer.

The input file needs to have the Computer Name, the MAC Address, and the IP address. Technically the Computer Name is not used for anything other than logging so if you really want to omit it you can, but you will get annoying error messages. The script assumes that you are using the defaults for the field names in PDQ Inventory. If the computer running the script does not have a NIC that resides on the same subnet as the target computer it will log an error and move to the next line. I am running this on my PDQ server but you could run it wherever you want. It can take the CSV file from a UNC path as well so you can set up a PDQ Inventory auto report that runs on a schedule like I am doing. I just have the report filtering to IP addresses on subnets that I want to wake.

If you want to perform the wakes on a schedule just set up a scheduled task that runs this script.

Here is the link to the github repo:



1 comment
Date Votes
  • I take it PDQ doesn't support IP directed broadcasts for WOL ? We will soon be splitting student PC's onto a different VLAN/subnet to staff PC's and this is going to cause me similar problems for wake on LAN as the server will remain on the staff VLAN and be accessible only via a router for student PC's.

    For IP directed broadcast WOL to work the router serving the remote subnet would need to have it enabled, (off by default in some routers) and PDQ would need to be aware of what the remote network address (including subnet) was, so that it can calculate the broadcast address of the foreign network from the network address and netmask. (I have not seen any configuration options like this however)

    Then it just sends WOL packets as unicast Ethernet frames to the specific broadcast IP address of the remote network rather than or the local broadcast address, it gets routed as a unicast packet to the destination router which then rebroadcasts it as an ethernet broadcast frame.