Advertisement
Guest User

Untitled

a guest
Jan 4th, 2013
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function send-wakeonlan{
  2.     param(
  3.         [string]$mac)
  4.     if (!($mac -like "*:*:*:*:*") -or ($mac -like "*-*-*-*-*")){
  5.     write-error "mac address not in correct format"
  6.     break
  7.     }
  8.  
  9.     $string=@($mac.split(":""-") | foreach {$_.insert(0,"0x")})
  10.     $target = [byte[]]($string[0], $string[1], $string[2], $string[3], $string[4], $string[5])
  11.  
  12.     $UDPclient = new-Object System.Net.Sockets.UdpClient
  13.     $UDPclient.Connect(([System.Net.IPAddress]::Broadcast),4000)
  14.     $packet = [byte[]](,0xFF * 102)
  15.     6..101 |% { $packet[$_] = $target[($_%6)]}
  16.     $UDPclient.Send($packet, $packet.Length) | out-null
  17. }
  18.  
  19. function wake-computer{
  20.     param(
  21.         [string]$computername)
  22.    
  23.     switch ($computername)
  24.     {
  25.         "tv" {$mac = "6C:62:6D:87:DB:A5"}
  26.         "seeker" {$mac = "0C:0C:0C:0C:01"}
  27.         "server" {$mac = "00:22:15:88:AE:29"}
  28.         "virwin" {$mac = "F4:6D:04:34:06:91"}
  29.     }
  30.  
  31.     if ($mac){
  32.     send-wakeonlan -mac $mac
  33.     }
  34.     else{WRITE-WARNING "Unknown computername: $computername"
  35.     }
  36. }
  37.  
  38.  
  39. "example"
  40. wake-computer -computername tv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement