Skip to content

Instantly share code, notes, and snippets.

@derhelge
Created September 26, 2023 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derhelge/1ce6d31f106beea37dfcb36591ac63a7 to your computer and use it in GitHub Desktop.
Save derhelge/1ce6d31f106beea37dfcb36591ac63a7 to your computer and use it in GitHub Desktop.
# .\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