To save energy costs at home, I have configured all my computers with Wakeup On Lan. With the use of an app on my mobile phone I can turn them on only when I need them.
Now I needed to start my Windows server once a week at a specific time. I checked the BIOS settings of my server. Unfortunately there were only two automatic turn on options: Every Day and Every Workday.
I am in the possession of another Windows server on the internet, which is always on. So I could use that server to schedule a script to run once a week.
So I decided to create a Powershell script that creates the magic packet and sends it to my home server.
#Define your variables here: $mac = 21-A2-2C-19-05-8A $DNS = mysite.domain.com $port = 9 $ip = [System.Net.Dns]::GetHostAddresses("$DNS") $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)}