mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-15 11:10:54 +01:00
Update wake-up.ps1
This commit is contained in:
parent
7cfe12f137
commit
e33c72470d
@ -6,9 +6,11 @@
|
||||
.PARAMETER MACaddress
|
||||
Specifies the host's MAC address (e.g. 11:22:33:44:55:66)
|
||||
.PARAMETER IPaddress
|
||||
Specifies the host's IP address or subnet address (e.g. 255.255.255.255)
|
||||
Specifies the host's IP address or subnet address (e.g. 192.168.0.255)
|
||||
.PARAMETER Port
|
||||
Specifies the UDP port (9 by default)
|
||||
.PARAMETER NumRetries
|
||||
Specifies number of retries (3 by default)
|
||||
.EXAMPLE
|
||||
PS> ./wake-up.ps1 11:22:33:44:55:66 192.168.100.100
|
||||
.LINK
|
||||
@ -17,7 +19,7 @@
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$MACaddress = "", [string]$IPaddress = "", [int]$Port=9)
|
||||
param([string]$MACaddress = "", [string]$IPaddress = "", [int]$Port=9, [int]$NumRetries=3)
|
||||
|
||||
function Send-WOL { param([string]$mac, [string]$ip, [int]$port)
|
||||
$broadcast = [Net.IPAddress]::Parse($ip)
|
||||
@ -32,14 +34,15 @@ function Send-WOL { param([string]$mac, [string]$ip, [int]$port)
|
||||
}
|
||||
|
||||
try {
|
||||
if ($MACaddress -eq "" ) { $MACaddress = Read-Host "Enter the host's MAC address (e.g. 00:11:22:33:44:55)" }
|
||||
if ($IPaddress -eq "" ) { $IPaddress = Read-Host "Enter the host's IP address or subnet address (e.g. 255.255.255.255)" }
|
||||
if ($MACaddress -eq "" ) { $MACaddress = Read-Host "Enter the host's MAC address (e.g. 11:22:33:44:55:66)" }
|
||||
if ($IPaddress -eq "" ) { $IPaddress = Read-Host "Enter the host's IP address or subnet address (e.g. 192.168.0.255)" }
|
||||
|
||||
Send-WOL $MACaddress $IPaddress $Port
|
||||
Start-Sleep -milliseconds 100
|
||||
Send-WOL $MACaddress $IPaddress $Port
|
||||
|
||||
"✔️ sent magic packet $MACaddress to IP $IPaddress on port $Port (twice)"
|
||||
for ($i = 0; $i -lt $NumRetries; $i++) {
|
||||
Start-Sleep -milliseconds 100
|
||||
Send-WOL $MACaddress $IPaddress $Port
|
||||
}
|
||||
"✔️ sent magic packet $MACaddress to IP $IPaddress on port $Port ($NumRetries retries)"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
Loading…
Reference in New Issue
Block a user