# wol - wake on lan powershell script. # # http://www.vistax64.com/powershell/46032-powershell-wol-script-testers-needed.html # I made this script for my blog, then realized I had no work for it, so could not test it. # anyone cares to test it for me ;-) # # choose one of the following options (depending on format of MAC adress to # fill the $mac Variable (change to MAC of target, only one needed if : used # change - in : of first option) # # placing the variable on a line by itself will write to screen: # $mac # # $mac = [byte[]]("00-0F-1F-20-2D-35".split('-') |% {[int]"0x$_"}) # $mac = [byte[]]("00:0F:1F:20:2D:35".split(':') |% {[int]"0x$_"}) # $mac # "000F1F202D35" -match "(..)(..)(..)(..)(..)(..)" | out-null # $mac = [byte[]]($matches[1..6] |% {[int]"0x$_"}) # $mac # $mac = [byte[]](0x00, 0x0F, 0x1F, 0x20, 0x2D, 0x35) # $mac # # debug # write-host $mac #writes $mac in decimal values # define mac address $vn1 = "00:11:25:A8:21:F4" # esxi1 vnic0 $vn2 = "00:11:25:A8:21:F5" # esxi1 vnic1 $vn3 = "00:0D:60:99:4C:6A" # esxi2 vnic0 $vn4 = "00:0D:60:99:4C:6B" # esxi2 vnic1 function wol { $mac = [byte[]]($args[0].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) } wol $vn1 wol $vn2 wol $vn3 wol $vn4 # pause #write-host -nonewline "Press any key to continue ..." #$x = $host.ui.rawui.readkey("noecho,includekeydown")