Created
September 26, 2023 14:57
-
-
Save derhelge/1ce6d31f106beea37dfcb36591ac63a7 to your computer and use it in GitHub Desktop.
This file contains 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
# .\sendWOL.ps1 -macAddress "8C:EC:4B:C2:68:CC" -computerName "r313-xyz" | |
param ( | |
[Parameter(Mandatory=$true)] | |
[string]$macAddress, | |
[Parameter(Mandatory=$true)] | |
[string]$computerName | |
) | |
# Überprüfen, ob die MAC-Adresse einem gültigen Format entspricht | |
if (-not ($macAddress -match '^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$')) { | |
Write-Error "Bitte geben Sie eine gültige MAC-Adresse im Format XX:XX:XX:XX:XX:XX ein." | |
exit 1 | |
} | |
# Interface basierend auf dem Computername auswählen | |
$interface = $null | |
if ($computerName -imatch '^r313') { | |
$interface = "optx" | |
} elseif ($computerName -imatch '^r201') { | |
$interface = "opty" | |
} else { | |
Write-Error "Ungültiger Computername. Kann kein Interface zuweisen." | |
exit 1 | |
} | |
# Define the URL and Credentials | |
$url = "https://firewall/api/wol/wol/set" | |
$credential = [System.Text.Encoding]::UTF8.GetBytes("key:secret") | |
$base64AuthInfo = [System.Convert]::ToBase64String($credential) | |
# Define the JSON payload | |
$body = @{ | |
wake = @{ | |
interface = $interface | |
mac = $macAddress | |
} | |
} | ConvertTo-Json | |
# Make the POST request | |
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization=("Basic " + $base64AuthInfo)} -Method Post -Body $body -ContentType "application/json" | |
# Output the response in a formatted manner | |
$response | ConvertTo-Json -Depth 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment