Link to home
Start Free TrialLog in
Avatar of Dustin Stanley
Dustin Stanley

asked on

How to Schedule A Task To Wake On Lan (WOL) All Other Computers (PCs) On A Network After I Start My Main Computer In Windows 7 Without Extra Applications

I have searched through google and there seems to be many ways to do this but most you have to install some sort of application. This is a learning curve for me but basically I have 4-5 other computers on a network that when I start the main computer (PC1) I want the other 4-5 computers to power on also.

I have experience with running scheduled tasks and I have enabled in the bios and my network cards to Wake On Lan (WOL). I have set automatic startups before using the task scheduler but this is not what I need. My schedule is to erratic.

It appears I need to send a "Magic Packet" and this is new to me. I am hoping I can run a Script of some kind in the task scheduler to send these magic packets out to the other PCs. I am using windows 7 on all the PCs.

Thank you for the help!
Avatar of Hello There
Hello There

First, all NICs must support WOL.
Wol requires the receipt of a Magic packet on a Nic that has wol enabled.
The magic packet has to be addressed to the physical address of the nic, MAC Address.

The process would be to install the network application capable of transmitting this magic packet, and the scheduled task is to run the task on boot, sending packets to each system

Are the distances among all the computers so vast or phrased better, I understand a dependency of all on the 1st computer that needs to be powered up first, what is the interdependency among the remaining?
SOLUTION
Avatar of Hello There
Hello There

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dustin Stanley

ASKER

Hello There
First, all NICs must support WOL.
They do.

Second, you cannot do it via Task Scheduler.
There is a option for On Startup.

Arnold
Are the distances among all the computers so vast or phrased better, I understand a dependency of all on the 1st computer that needs to be powered up first, what is the interdependency among the remaining?
This part I don't get 100%. The main PC controls a Backend of a Database and the computers are spread out.

Also I found this online but as I said I am very new to this area. Does this look legitimate and how would I execute it exactly???
param (\\[String\\]$MACAddrString = $(throw 'No MAC addressed passed, please pass as xx:xx:xx:xx:xx:xx'))
 $MACAddr = $macAddrString.split(':') | %\\{ \\[byte\\]('0x' + $_) \\}
 if ($MACAddr.Length -ne 6)
 \\{
     throw 'MAC address must be format xx:xx:xx:xx:xx:xx'
 \\}
 $UDPclient = new-Object System.Net.Sockets.UdpClient
 $UDPclient.Connect((\\[System.Net.IPAddress\\]::Broadcast),4000)
 $packet = \\[byte\\[\\]\\](,0xFF * 6)
 $packet += $MACAddr * 16
 \\[void\\] $UDPclient.Send($packet, $packet.Length)
 write "Wake-On-Lan magic packet sent to $MACAddrString, length $($packet.Length)"

Open in new window

Appears to be powershell.

You can not run on boot per se, your execute has to wait until the network sets up or, the task will run firing packets that go nowhere.

The on boot task could be to schedule the transmission of the magic packets 10 minutes later as a single event presuming this shoukd be enough for the system's network to come up.

In your case you would read the MAC addresses from a file and loop through them sending packet.

Ms has a powershell cmdlet reference.

The following deals with the new-object call, https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/new-object?view=powershell-5.1

It has to be tested against the version on your system, you mentioned Windows 7, the implementation might be different.
I know there is such an option (if you would read my post properly you would notice that this function is a part of my suggestion). I am just talking about impossibility to use this on CLIENT machines in your situation. Thanks for understanding.
In the Powershell Function Script that Hello There provided in the link above it looks like this:
function Send-WOL
{
<# 
  .SYNOPSIS  
    Send a WOL packet to a broadcast address
  .PARAMETER mac
   The MAC address of the device that need to wake up
  .PARAMETER ip
   The IP address where the WOL packet will be sent to
  .EXAMPLE 
   Send-WOL -mac 00:11:32:21:2D:11 -ip 192.168.8.255 
#>

[CmdletBinding()]
param(
[Parameter(Mandatory=$True,Position=1)]
[string]$mac,
[string]$ip="255.255.255.255", 
[int]$port=9
)
$broadcast = [Net.IPAddress]::Parse($ip)
 
$mac=(($mac.replace(":","")).replace("-","")).replace(".","")
$target=0,2,4,6,8,10 | % {[convert]::ToByte($mac.substring($_,2),16)}
$packet = (,[byte]255 * 6) + ($target * 16)
 
$UDPclient = new-Object System.Net.Sockets.UdpClient
$UDPclient.Connect($broadcast,$port)
[void]$UDPclient.Send($packet, 102) 

}

Open in new window


On that page it states for "Usage" to pass the argument or parameter like so:
Send-WOL -mac 00:11:32:21:2D:11 -ip 192.168.8.255 -port 7 
 
Send-WOL -mac 00-11-32-21-2D-11 -ip 192.168.8.255 -port 7 
 
Send-WOL -mac 0011.3221.2D11 -ip 192.168.8.255 -port 7 
 
Send-WOL -mac 001132212D11 -ip 192.168.8.255 -port 7 
 
Send-WOL -mac 001132212D11 

Open in new window



But how do I exactly pass this to the Powershell Function? I am very new to this area. I mainly work in VBA for Access. Do I set up a batch file to run with the argument in it or what?

Thank you all for the help.
Save it as PS1 -> create a task and let it run.
I have been trying every which way with no luck from the Task Scheduler.  

In Arguments I have Tried:
-ExecutionPolicy Bypass "C:\Users\User 1\Downloads\Send-WOL.ps1" Send-WOL -mac 000000000000
-ExecutionPolicy Bypass "C:\Users\User 1\Downloads\Send-WOL.ps1" Send-WOL -mac 00:00:00:00:00:00 -ip 00.0.0.000 -port 7
-ExecutionPolicy Bypass "C:\Users\User 1\Downloads\Send-WOL.ps1" Send-WOL -mac 00:00:00:00:00:00 -ip 00.0.0.000
-ExecutionPolicy Bypass C:\Users\User 1\Downloads\Send-WOL.ps1 Send-WOL -mac 00:00:00:00:00:00 -ip 00.0.0.000 -port 7
-ExecutionPolicy Bypass C:\Users\User 1\Downloads\Send-WOL.ps1 Send-WOL -mac 00:00:00:00:00:00 -ip 00.0.0.000
-ExecutionPolicy Bypass Send-WOL.ps1 Send-WOL -mac 00:00:00:00:00:00

Open in new window


I have tried Start in:
C:\Users\User 1\Downloads\
"C:\Users\User 1\Downloads\"

Open in new window


No luck. With user logged in or with user logged in/out. Highest Privileges....
you modify the example for a WOL on request
to a loop that reads MAC addresses of your systems in a file, and then issues a WOL to each system.
Create a single file, computers_to_wakeup.txt
00:11:32:21:2D:11
.
.
.


Never use an IP since it will not be valid when the system is off, the 255.255.255.255 is a broadcast address which is what the WOL packet is destined for the MAC address of the NIC....

https://social.technet.microsoft.com/Forums/windows/en-US/78d5a5fa-bb82-4c2d-a2c1-96d518b9bd74/need-to-read-text-file-as-an-array-and-get-elements-from-each-line-of-array-using-powershell?forum=winserverpowershell

A way to read a csv file if you want to include
systemname,MAC address
and have the output reflect issued WOL to systemname Mac address: ...

the data extracted from the file is the loop surrounding the example.

first test the script manually before trying to scheduling it.
i.e. make sure it works, before proceeding to the next step.
Boot the system that is first. then run this script and see if the other system boot.

Many systems have BIOS start options.
You could schedule the boot every morning of the first at 8am as an example, while scheduling the others to boot 10 minutes later.
The code designers remarks are "default UDP port is 9". According to http://canyouseeme.org/ my port 9 is not seen. Do I have to open this port in my router to be able to WOL within my network?  If I do have to open and forward this port then how would I do this on multiple PCs if the single 9 port is forwarded to the 1 PC? Thank you for the help but so far not going so well.
No, it is a broadcast packet addressed to a Mac address, each NIC will identify the packet addressed to it as long as the NIC is powered.

Forwarding etc. applies when the Windows OS is operational and analyzes the network packets passed by the Nic to the kernel network handler.

In this situation the Windows OS is off. The magic packet triggers the NIC to trigger the MB to start the bootup process.
On PC1 is there anywhere I would need to enable something to be able to SEND the magic packets. Like how I had to enable WOL by Magic Packets?

Also here is my system setup currently. I don't know if this will help you any.
User generated image
no, all you need is the powershell script and the MAC address of the other devices to which you want the packet sent.

In the way you have it, if pc1 and pc2 are on different segments, than you will run into an issue, the magic packet can not cross segment boundaries so if PC1 is on 192.168.0.x/24 and PC2 is on 192.168.2.y/24 you will not be able to wake it up.

The only way would if your gateway supports it, to send the magic packet from the gateway.
Arnold
so if PC1 is on 192.168.0.x/24 and PC2 is on 192.168.2.y/24
Maybe I'm misunderstanding but both PCs have completely different IP address (IPv4 Address) such as:
PC1 = 10.1.0.125
PC2 = 10.1.0.724

Also the gateway and the first switch are basically just a router from the Service provider.

I just want to clarify this before I start thinking a different path. I thank you for the help.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the help. i am just going to set back up the scheduled power on at a certain time.