#------------------------------------------------------------------------------- # Wake On Lan (WOL) PowerShell Script. # # http://www.vistax64.com/powershell/46032-powershell-wol-script-testers-needed.html # # Debugging Notes: # # placing the variable on a line by itself will echo to screen (as byte array): # $mac # placing the variable after write-host will echo to screen as decimal values: # write-host $mac #writes $mac in decimal values # # $mac address configuration # choose one of the following methods to define the $mac address variable. # # method 1: # $mac = [byte[]]("00-0F-1F-20-2D-35".split('-') |% {[int]"0x$_"}) # $mac = [byte[]]("00:0F:1F:20:2D:35".split(':') |% {[int]"0x$_"}) # method 2: # "000F1F202D35" -match "(..)(..)(..)(..)(..)(..)" | out-null # $mac = [byte[]]($matches[1..6] |% {[int]"0x$_"}) # method 3: # $mac = [byte[]](0x00, 0x0F, 0x1F, 0x20, 0x2D, 0x35) # show results: # $mac #------------------------------------------------------------------------------- # define mac address $mac = [byte[]]("00:0F:1F:20:2D:35".split(':') |% {[int]"0x$_"}) # send wol packet via broadcast $udpclient = new-object system.net.sockets.udpclient $udpclient.connect(([system.net.ipaddress]::broadcast),4000) $packet = [byte[]](,0xFF * 102) 6..101 |% {$packet[$_] = $mac[($_%6)]} $udpclient.send($packet,$packet.length) # # pause write-host -nonewline "Press any key to continue ..." $x = $host.ui.rawui.readkey("noecho,includekeydown")