Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function send-wakeonlan{
- param(
- [string]$mac)
- if (!($mac -like "*:*:*:*:*") -or ($mac -like "*-*-*-*-*")){
- write-error "mac address not in correct format"
- break
- }
- $string=@($mac.split(":""-") | foreach {$_.insert(0,"0x")})
- $target = [byte[]]($string[0], $string[1], $string[2], $string[3], $string[4], $string[5])
- $UDPclient = new-Object System.Net.Sockets.UdpClient
- $UDPclient.Connect(([System.Net.IPAddress]::Broadcast),4000)
- $packet = [byte[]](,0xFF * 102)
- 6..101 |% { $packet[$_] = $target[($_%6)]}
- $UDPclient.Send($packet, $packet.Length) | out-null
- }
- function wake-computer{
- param(
- [string]$computername)
- switch ($computername)
- {
- "tv" {$mac = "6C:62:6D:87:DB:A5"}
- "seeker" {$mac = "0C:0C:0C:0C:01"}
- "server" {$mac = "00:22:15:88:AE:29"}
- "virwin" {$mac = "F4:6D:04:34:06:91"}
- }
- if ($mac){
- send-wakeonlan -mac $mac
- }
- else{WRITE-WARNING "Unknown computername: $computername"
- }
- }
- "example"
- wake-computer -computername tv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement