Added try and catch

This commit is contained in:
Markus Fleschutz
2020-10-05 13:12:12 +02:00
parent 14ab054646
commit 847be37772
25 changed files with 199 additions and 110 deletions

View File

@ -42,17 +42,20 @@ $UDPclient.Connect($broadcast,$port)
$Hostname = read-host "Enter hostname: "
$MyMACAddresses = "io=11:22:33:44:55:66","pi=11:22:33:44:55:66"
foreach($item in $MyMACAddresses) {
$array = $item.Split("=")
$thisHost=$array[0]
$thisMAC=$array[1]
if ($thisHost -like $Hostname) {
Send-WOL $thisMAC
write-output "✔️ host $thisHost waked up (MAC $thisMAC)"
exit 0
try {
foreach($item in $MyMACAddresses) {
$array = $item.Split("=")
$thisHost=$array[0]
$thisMAC=$array[1]
if ($thisHost -like $Hostname) {
Send-WOL $thisMAC
write-output "✔️ host $thisHost waked up (MAC $thisMAC)"
exit 0
}
}
}
echo "Sorry, hostname $Hostname is unknown."
pause
echo "Sorry, hostname $Hostname is unknown."
pause
exit 1
} catch { Write-Error $Error[0] }
exit 1