Update SVSTaskGate.ps1

This commit is contained in:
2025-01-04 03:27:36 -05:00
parent 8d33a0395b
commit 92624a26a4

View File

@@ -715,7 +715,19 @@ function GetHtmlContent {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ installRMMCommand, UID, Name })
})
.then(response => {
if (!response.ok) {
appendLog(`Error: ${response.statusText}`, "red");
throw new Error(`Server responded with status ${response.status}`);
}
return response.text();
})
.then(data => {
appendLog(`Response: ${data}`, "green");
})
.catch(error => {
appendLog(`Fetch error: ${error.message}`, "red");
});
}
@@ -862,14 +874,18 @@ try {
$body = $bodyStream.ReadToEnd()
$selectedSite = ConvertFrom-Json $body
# Extract parameters
$ApiUrl = $selectedSite.ApiUrl
$ApiKey = $selectedSite.ApiKey
$ApiSecretKey = $selectedSite.ApiSecretKey
# Log received data
Write-LogHybrid -Message "Received data: $($body)" -Level "Info"
# Verify required parameters
if (-not $ApiUrl -or -not $ApiKey -or -not $ApiSecretKey) {
$responseString = "Error: Missing required parameters. ApiUrl='$ApiUrl', ApiKey='$ApiKey', ApiSecretKey='$ApiSecretKey'"
# Extract values from $selectedSite
$installRMMCommand = $selectedSite.installRMMCommand
$UID = $selectedSite.UID
$Name = $selectedSite.Name
# Validate required fields
if (-not $installRMMCommand) {
$responseString = "Error: Missing 'installRMMCommand' in the request payload."
Write-LogHybrid -Message $responseString -Level "Error"
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString)
$response.ContentType = "text/plain"
$response.ContentLength64 = $buffer.Length
@@ -878,11 +894,35 @@ try {
return
}
Write-LogHybrid -Message "Executing command: $installRMMCommand" -Level "Info"
Write-LogHybrid -Message "Site UID: $UID, Name: $Name" -Level "Info"
try {
# Execute the command
Invoke-Expression $installRMMCommand
$responseString = "RMM install triggered successfully for site: $Name (UID: $UID)."
Write-LogHybrid -Message $responseString -Level "Success"
}
catch {
$responseString = "Error executing RMM install: $($_.Exception.Message)"
Write-LogHybrid -Message $responseString -Level "Error"
}
# Send the response back to the client
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString)
$response.ContentType = "text/plain"
$response.ContentLength64 = $buffer.Length
$response.OutputStream.Write($buffer, 0, $buffer.Length)
$response.OutputStream.Close()
}
}
"/setSVSPowerplan" {
if ($request.HttpMethod -eq "GET") {
Set-SVSPowerPlan