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