Last active
January 23, 2023 17:13
-
-
Save LuMarans30/c4e559542357c88fe22763ce99c10f91 to your computer and use it in GitHub Desktop.
A simple powershell script to turn on a computer in the same network knowing its MAC address (you must enable the wake on lan function in the BIOS/UEFI of the target).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $Mac = $null | |
| if ($args.count -eq 1 ) { | |
| $Mac = $args[0] | |
| $Mac | out-file -filepath .\mac.txt -width 200 | |
| Write-Output "The next time you won't have to re-enter the MAC address because it has been saved on a file in this directory." | |
| } | |
| else{ | |
| $file_data = Get-Content .\mac.txt | |
| if ( $file_data -eq $null ) { | |
| Write-Output "error: please enter a MAC address" | |
| exit | |
| } | |
| else{ | |
| $Mac = $file_data | |
| Write-Output "The previously used MAC adress is $Mac" | |
| } | |
| } | |
| $MacByteArray = $Mac -split "[:-]" | ForEach-Object { [Byte] "0x$_"} | |
| [Byte[]] $MagicPacket = (,0xFF * 6) + ($MacByteArray * 16) | |
| $UdpClient = New-Object System.Net.Sockets.UdpClient | |
| $UdpClient.Connect(([System.Net.IPAddress]::Broadcast),7) | |
| $UdpClient.Send($MagicPacket,$MagicPacket.Length) | |
| $UdpClient.Close() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is my first powershell script, please leave a comment if you notice any possible bugs or optimizations. Thanks! 🙂